上那些三维numpy的阵列我有2个numpy的阵列output
和index
:装满基于2D阵列具有索引
output = np.zeros((3,3,3))
>>>index
array([[0,1,2],
[1,0,0],
[2,2,2]])
index
表示直到其output
应与那些在第一维填入的索引。的output
的填充值应该是这样的:
>>>output
array([[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]],
[[0, 1, 1],
[1, 0, 0],
[1, 1, 1]],
[[0, 0, 1],
[0, 0, 0],
[1, 1, 1]]]
例如,由于index[0, 1] == 1
,我们设置output[:1+1, 0, 1] = 1
。一般来说,如果index[i, j] == k
,我们设置output[:k+1, i, j] = 1
。
有谁知道如何以矢量化的方式实现这一点?