Numpy Shape
import numpy as np
a = np.array([1, 2, 4, 5])
print(a)
[1 2 4 5]
a
array([1, 2, 4, 5])
a.shape
(4,)
# change the shape
a.shape = (2, 2)
a
array([[1, 2],
[4, 5]])
print(a)
[[1 2]
[4 5]]
b = np.array([[1, 3, 5, 2, 4], [8, 6, 9, 7, 10]])
print(b)
[[ 1 3 5 2 4]
[ 8 6 9 7 10]]
b.shape
(2, 5)
b.shape = (5, 2)
print(b)
[[ 1 3]
[ 5 2]
[ 4 8]
[ 6 9]
[ 7 10]]
b.shape = (10, 1)
print(b)
[[ 1]
[ 3]
[ 5]
[ 2]
[ 4]
[ 8]
[ 6]
[ 9]
[ 7]
[10]]
# get the numebr of array dimension
print(b.ndim)
2