我刚刚偶然发现了一个我不太理解的 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 和 python 2.7.11 上看到这个