Hi,
The following code sample should do what you want:
import torch

inp = torch.rand(2, 3, 3, 4)
idx = torch.LongTensor([[0,0,0], [1,1,1], [0, 1, 2]])

b, s1, s2, s3 = inp.size()
# Note that for a contiguous tensor,
# inp.stride(-1) = 1
# inp.stride(-2) = s3
# inp.stride(-3) = s3*s2
lin_idx = idx.select(1, -1)*inp.stride(-1) + \
          idx.select(1, -2)*inp.stride(-2) + \
          idx.select(1, -3)*inp.stride(-3)

tmp_inp = inp.view(b, s1*s2*s3)
tmp_inp.index_fill_(1, lin_idx, 1)

print(inp)