Solved by ptrblck in post #4 
              
              
                Yes, in that case my approach would work and you can compare the results as: 
inds = torch.tensor([3,5,7,8])
input = torch.tensor([5,5,5,8,8,3,7,3,7])
a = input.clone()
b = input.clone()
for i, ind in enumerate(inds):
    a[a==ind] = i
    
idx = (b.unsqueeze(0) == inds.unsqueeze(1)).nonzero()
b[idx…