size of NumPy array

前端 未结 2 419
天涯浪人
天涯浪人 2020-12-29 01:59

Is there an equivalent to the MATLAB

 size()

command in Numpy?

In MATLAB,

>>> a = zeros(2,5)
 0 0 0 0 0
         


        
2条回答
  •  礼貌的吻别
    2020-12-29 02:34

    This is called the "shape" in NumPy, and can be requested via the .shape attribute:

    >>> a = zeros((2, 5))
    >>> a.shape
    (2, 5)
    

    If you prefer a function, you could also use numpy.shape(a).

提交回复
热议问题