小编Pau*_*tti的帖子

使用 numpy 进行奇怪的索引

我有一个变量 x,形状为 (2,2,50,100)。

我还有一个数组 y,它等于 np.array([0,10,20])。当我索引 x[0,:,:,y] 时会发生一件奇怪的事情。

x = np.full((2,2,50,100),np.nan)
y = np.array([0,10,20])
print(x.shape)
(2,2,50,100)
print(x[:,:,:,y].shape)
(2,2,50,3)
print(x[0,:,:,:].shape)
(2,50,100)
print(x[0,:,:,y].shape)
(3,2,50)
Run Code Online (Sandbox Code Playgroud)

为什么最后一个输出 (3,2,50) 而不是 (2,50,3)?

python numpy

30
推荐指数
2
解决办法
968
查看次数

标签 统计

numpy ×1

python ×1