In [3]: a.ndim # num of dimensions/axes, *Mathematics definition of dimension*
Out[3]: 2
轴/轴
在Numpy中索引 array 的第n个坐标 . 多维数组每个轴可以有一个索引 .
In [4]: a[1,0] # to index `a`, we specific 1 at the first axis and 0 at the second axis.
Out[4]: 3 # which results in 3 (locate at the row 1 and column 0, 0-based index)
形状
描述沿每个可用轴的数据(或范围) .
In [5]: a.shape
Out[5]: (2, 2) # both the first and second axis have 2 (columns/rows/pages/blocks/...) data
6 回答
它是.shape:
从而:
shape
方法要求a
是Numpy ndarray . 但Numpy还可以计算纯python对象的可迭代形状:你可以使用.shape
您可以使用
.ndim
作为尺寸,使用.shape
来了解确切的尺寸您可以使用
.reshape
函数更改尺寸第一名:
按照惯例,在Python世界中,
numpy
的快捷方式是np
,所以:第二名:
在Numpy中, dimension , axis/axes , shape 是相关的,有时是类似的概念:
维度
在数学/物理学中,维度或维度被非正式地定义为指定空间中任何点所需的最小坐标数 . 但是在Numpy中,根据numpy doc,它与轴/轴相同:
轴/轴
在Numpy中索引
array
的第n个坐标 . 多维数组每个轴可以有一个索引 .形状
描述沿每个可用轴的数据(或范围) .
如果输入不是numpy数组而是列表列表,也可以工作
或元组元组