1

我有一个 3d 数组numpy,我想在其中两个轴上建立索引。对于其中一个轴,我使用简单的整数索引,而在另一个轴上,我使用列表索引。如果我单独应用索引,结果与我在一对括号内应用它们时的结果不同:

import numpy as np
a = np.ones((10, 20, 30))

print(a.shape)
> (10, 20, 30)

# the unexpected result:
print(a[3,:,[1,2]].shape)
> (2, 20)

# the two expected results:
print(a[3][:,[1,2]].shape)
> (20, 2)

print(a[:,:,[1,2]][3].shape)
> (20, 2)

您能否向我解释为什么这是预期/期望的行为?对我来说,这看起来不一致。

4

0 回答 0