等效Numpy数组索引返回不同的结果

时间:2017-03-01 22:28:31

标签: python numpy

我不确定这两种索引方法是否相同,但直观上应该是这样。

说我们有

x = np.arange(6).reshape(1, 3, 2)
idx = np.array([0, 1])

x现在

array([[[0, 1],
        [2, 3],
        [4, 5]]])

x[0, :, idx]返回(有些意料之外):

array([[0, 2, 4],
       [1, 3, 5]])

x[0][:, idx]或等效x.squeeze()[:, idx]返回时:

array([[0, 1],
       [2, 3],
       [4, 5]])

为什么会这样?他们不应该返回相同的结果吗?

0 个答案:

没有答案
相关问题