xxxxxxxxxx
>>> a = np.array([(1, 2), (3, 4)], dtype=[('x', 'i4'), ('y', 'i4')])
>>> np.shape(a)
(2,)
>>> a.shape
(2,)
xxxxxxxxxx
>>> np.shape(np.eye(3))
(3, 3)
>>> np.shape([[1, 2]])
(1, 2)
>>> np.shape([0])
(1,)
>>> np.shape(0)
()
xxxxxxxxxx
import numpy as np
data = np.arange(2*3*4*5).reshape(2, 3, 4, 5)
print(data)
this is the breakdown :
{ [()()(a,a,a,a,a)()] [()()()()] [()()()()] } { [()()()()] [()()()()] [()()()()] }
tow of {} ^5 items inside each
three of []
four of ()
each (a,a,a,a,a) has 5 items
example will be like this
[[[[ 0 1 2 3 4]
[ 5 6 7 8 9]
[10 11 12 13 14]
[15 16 17 18 19]]
[[20 21 22 23 24]
[25 26 27 28 29]
[30 31 32 33 34]
[35 36 37 38 39]]
[[40 41 42 43 44]
[45 46 47 48 49]
[50 51 52 53 54]
[55 56 57 58 59]]]
^two
^three
^four , five items in each
[[[60 61 62 63 64]
[65 66 67 68 69]
[70 71 72 73 74]
[75 76 77 78 79]]
[[80 81 82 83 84]
[85 86 87 88 89]
[90 91 92 93 94]
[95 96 97 98 99]]
[[100 101 102 103 104]
[105 106 107 108 109]
[110 111 112 113 114]
[115 116 117 118 119]]]]
xxxxxxxxxx
a = np.arange(3)
b = np.arange(12).reshape((3, 4))
c = np.arange(24).reshape((2, 3, 4))
# it returns the length of each dimension (=size function of MATLAB)
print(a.shape) # (3,)
print(b.shape) # (3, 4)
print(c.shape) # (2, 3, 4)
xxxxxxxxxx
import numpy as np
# Assuming 'arr' is the numpy array whose shape needs to be determined
arr = np.array([[1, 2, 3], [4, 5, 6]])
shape = arr.shape
print(shape)