numpy.shape#
- numpy.shape(a)[源代码]#
返回数组的形状。
- 参数:
- a类数组对象
输入数组。
- 返回:
- shape整数元组
形状元组的元素给出对应数组维度的长度。
另请参阅
lenlen(a)对于 N>=1 的 N 维数组等效于np.shape(a)[0]。ndarray.shape等效的数组方法。
示例
>>> import numpy as np >>> np.shape(np.eye(3)) (3, 3) >>> np.shape([[1, 3]]) (1, 2) >>> np.shape([0]) (1,) >>> np.shape(0) ()
>>> a = np.array([(1, 2), (3, 4), (5, 6)], ... dtype=[('x', 'i4'), ('y', 'i4')]) >>> np.shape(a) (3,) >>> a.shape (3,)