Python 巨蟒;冒号和省略号索引的区别
我一直在试验使用冒号和省略号的Numpy数组索引。然而,我无法理解我得到的结果 下面是示例代码:Python 巨蟒;冒号和省略号索引的区别,python,numpy,indexing,ellipsis,colon,Python,Numpy,Indexing,Ellipsis,Colon,我一直在试验使用冒号和省略号的Numpy数组索引。然而,我无法理解我得到的结果 下面是示例代码: >>> a = np.array([[1,2],[3,4]]) >>> a array([[1, 2], [3, 4]]) >>> a[:,np.newaxis] # <-- the shape of the rows are unchanged array([[[1, 2]], [[3, 4]]]
>>> a = np.array([[1,2],[3,4]])
>>> a
array([[1, 2],
[3, 4]])
>>> a[:,np.newaxis] # <-- the shape of the rows are unchanged
array([[[1, 2]],
[[3, 4]]])
>>> a[...,np.newaxis] # <-- the shape of the rows changed from horizontal to vertical
array([[[1],
[2]],
[[3],
[4]]])
>a=np.array([[1,2],[3,4]]
>>>a
数组([[1,2],
[3, 4]])
>>>原文是(2,2)
使用:,它将变为(2,1,2)。在第一个尺寸标注之后添加的新轴
与。。。形状为(2,2,1),新形状最后添加