【发布时间】:2020-06-04 21:56:06
【问题描述】:
假设我有一个形状为 [z, y, x] 的 numpy 数组 a 和另一个数组 b形状:[y, x]。
数组 b 包含沿 z 的索引,我想为每个 y 和 x 从 a 中提取这些索引.
到目前为止,我有以下不雅的方法:
from_a = np.full_like(b, np.nan)
for i in range(y):
for j in range(x):
des_ind = b[i,j]
from_a[i,j] = a[des_ind,i,j]
有没有很好的 Pythonic 方式来做到这一点?
【问题讨论】:
-
你看过花哨的索引吗?
标签: python numpy multidimensional-array indexing numpy-ndarray