Solved by LeviViana in post #2 
              
              
                I’m not sure I got your point. If you want to know how to use the indexes to sort a tensor, then this snippet could help: 
import torch
k  = torch.tensor([[2, 9, 3],
             [8, 0, 0]])
sorted_k, indx = k.sort()
sorted_k_again = k.gather(1, indx)
sorted_k_again.equal(sorted_k) # <- prints True

…