Reserved one-dimensional array of slice dimension information after Numpy

Reserved one-dimensional array of sliced ​​dimension information

>>> x
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])
>>> a=x[:,0]
>>> a
array([0, 3, 6])
>>> a.shape
(3,)
#丢失维度信息
>>> a=x[:,0,None]
>>> a
array([[0],
       [3],
       [6]])
>>> a.shape
(3, 1)
#未丢失维度信息
>>> a=x[None,:,0]
>>> a
array([[0, 3, 6]])
>>> a.shape
(1, 3)
#未丢失维度信息

Guess you like

Origin www.cnblogs.com/redo19990701/p/11469868.html