Mon*_*eck 6 python numpy variable-length multidimensional-array
如果我使用len(np.array([[2,3,1,0], [2,3,1,0], [3,2,1,1]]))
,我会回来3.
为什么len()
关于哪个轴我想要多维数组的长度没有争论?这令人震惊.还有其他选择吗?
hpa*_*ulj 13
什么是len
等效的嵌套列表?
len([[2,3,1,0], [2,3,1,0], [3,2,1,1]])
Run Code Online (Sandbox Code Playgroud)
通过更一般的概念shape
,numpy
开发人员选择实施__len__
作为第一维度.Python映射len(obj)
到obj.__len__
.
X.shape
返回一个元组,它有一个len
- 维度的数量,X.ndim
. X.shape[i]
选择ith
维度(元组索引的直接应用).
简单.使用.shape
.
>>> nparray.shape
(5, 6) #Returns a tuple of array dimensions.
Run Code Online (Sandbox Code Playgroud)