numpy.shape(shape, dtype=None, order='C')
Return tuple with details of the array.
a | array input |
One Dimensional array ( 1-D ) : (n, ) :tuple elements = 1
Two Dimensional array ( 2-D ) : (n,m ) :tuple elements = 2
Three Dimensional array ( 3-D) : (n,m,j) : tuple elements = 3
Four Dimensional array ( 4-D ) : (n,m,j,k): tuple elements = 4
Shape: (3, 4) Dimension 2 | Shape: (4, 3) Dimension 2 |
import numpy as np
ar=np.ones((3,))
print(ar)
print("Shape: ", ar.shape)
print("Dimension ", ar.ndim)
Output
[1. 1. 1.]
Shape: (3,)
Dimension 1
import numpy as np
ar=np.ones((3,2))
print(ar)
print("Shape: ", ar.shape)
print("Dimension ", ar.ndim)
Output
[[1. 1.]
[1. 1.]
[1. 1.]]
Shape: (3, 2)
Dimension 2
import numpy as np
ar=np.ones((3,2,3))
print(ar)
print("Shape: ", ar.shape)
print("Dimension ", ar.ndim)
Output
[[[1. 1. 1.]
[1. 1. 1.]]
[[1. 1. 1.]
[1. 1. 1.]]
[[1. 1. 1.]
[1. 1. 1.]]]
Shape: (3, 2, 3)
Dimension 3
import numpy as np
ar=np.ones((3,2,3,4))
print(ar)
print("Shape: ", ar.shape)
print("Dimension ", ar.ndim)
Output
[[[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]
[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]]
[[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]
[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]]
[[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]
[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]]]
Shape: (3, 2, 3, 4)
Dimension 4
reshape() : Change shape or dimension of the input array