我刚刚偶然发现了一个我不太明白的numpy索引行为。看起来numpy正在改变我的坐标轴的顺序,这取决于索引模式。不幸的是,我无法在文档中找到对以下内容的解释。有人可以向我解释发生了什么事吗?Numpy索引重新排列数组
# This is expected: dimension 1 is reduced to length 1:
print np.ndarray(shape=(3,3,3,3))[:, [0], :, :].shape
>>> (3, 1, 3, 3)
# This is the unexpected behavior:
print np.ndarray(shape=(3,3,3,3))[:, [0], :, 0].shape
>>> (1, 3, 3)
我期望第二个命令产生(3,1,3)。如果我从第四个角度选择一个元素,为什么前两个维度的形状会发生变化? 非常感谢!
编辑: 我见到这对numpy的1.11.0与蟒蛇2.7.11
尽管很晦涩,但这种行为[记录](http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#combining-advanced-and-basic-indexing)。 – 2016-06-21 09:37:26