numpy.shape#

numpy.shape(a)[原始碼]#

傳回陣列的形狀。

參數:
aarray_like

輸入陣列。

傳回值:
shapetuple of ints

形狀元組的元素給出相應陣列維度的長度。

參見

len

len(a) 等效於 np.shape(a)[0],對於 N 維陣列且 N>=1

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,)