Why does the program
import numpy as np
c = np.array([1,2])
print(c.shape)
d = np.array([[1],[2]]).transpose()
print(d.shape)
give
<
len(c.shape)
is the "depth" of the array.
For c
, the array is just a list (a vector), the depth is 1.
For d
, the array is a list of lists, the depth is 2.
Note:
c.transpose()
# array([1, 2])
which is not d
, so this behaviour is not inconsistent.
dt = d.transpose()
# array([[1],
# [2]])
dt.shape # (2,1)