- shape() is Python Numpy method that find or return the actual shape of the given Array.
- It return the order of the matrix.
Example-
array is [1 2]
Shape is (2,)
array is
[[1,2]
[3,4]]
Shape is (2,2)
Syntax-
shape=numpy.shape(array)
program-
#import numpy
import numpy as np
l=[1,2,3,4]
arr=np.array(l)
print("Array isn",arr)
print("And Shape is",arr.shape)
l=[[1,2,3],[3,2,1],[1,0,1]]
arr=np.array(l)
print("nArray isn",arr)
print("And Shape is",arr.shape)
l=[[[1,2],[2,1]],[[3,4],[4,3]]]
arr=np.array(l)
print("nArray isn",arr)
print("And Shape is",arr.shape)
Array is
[1 2 3 4]
And Shape is (4,)
Array is
[[1 2 3]
[3 2 1]
[1 0 1]]
And Shape is (3, 3)
Array is
[[[1 2]
[2 1]]
[[3 4]
[4 3]]]
And Shape is (2, 2, 2)