bz=2,
h = 5
w = 5
a = torch.zeros(bz, h, w)
idx_1 = torch.tensor([[0,2,1],[2,3,0]])
idx_2 = torch.tensor([[1,2,3],[3,3,4]])
# Is it possible to remove `for loop` here ?
for i in range(bz):
a[i][idx_1[i], idx_2[i]] = 1
Expected results:
tensor([[[0,1,0,0,0],
[0,0,0,1,0],
[0,0,1,0,0],
[0,0,0,0,0],
[0,0,0,0,0]],
[[0,0,0,0,1],
[0,0,0,0,0],
[0,0,0,1,0],
[0,0,0,1,0],
[0,0,0,0,0]]])