Solved by googlebot in post #4 
              
              
                can’t say that gather() is fast, but following should be a loop-less equivalent for reading 
target.gather(-1,index.unsqueeze(1).expand(-1,nsamples,-1))

for writing, look at Tensor.scatter_ or Tensor.masked_fill_, expanding index/mask similarly