Difference between single and double bracket Numpy array?

前端 未结 3 1715
予麋鹿
予麋鹿 2021-02-01 08:22

What is the difference between these two numpy objects?

import numpy as np
np.array([[0,0,0,0]])
np.array([0,0,0,0])
3条回答
  •  粉色の甜心
    2021-02-01 09:12

    In [71]: np.array([[0,0,0,0]]).shape
    Out[71]: (1, 4)
    
    In [72]: np.array([0,0,0,0]).shape
    Out[72]: (4,)
    

    The former is a 1 x 4 two-dimensional array, the latter a 4 element one-dimensional array.

提交回复
热议问题