the dimensions from the advanced indexing operations are inserted into the result array at the same spot as they were in the initial array (the latter logic is what makes simple advanced indexing behave just like slicing).
In [12]: a = np.arange(9).reshape(3,3)
In [13]: a[:,1].shape
Out[13]: (3,)
In [14]: a[:,[1]].shape
Out[14]: (3, 1)
In [15]: a[:,[1,2]].shape
Out[15]: (3, 2)
In [16]: a[:,[[1,2],[0,1]]].shape
Out[16]: (3, 2, 2)
a[:, 1]
是{a1}的一个例子。在a[:, [1]]
是combining advanced and basic indexing的一个例子。:
是一个基本片,但是[1]
触发了高级整数索引。在由于高级索引都是相邻的,the rules用于组合高级索引和基本索引,例如
因此,整数索引
[1]
,它作为一个数组的形状应该是(1,)
,它会导致插入同一形状的额外维度 结果呢。在相关问题 更多 >
编程相关推荐