Hi Bin!
If you represent your permutation as a vector of permuted integers
(as you do), you may use argsort()
to obtain the inverse permutation:
>>> import torch
>>> torch.__version__
'1.7.1'
>>> p1 = torch.tensor ([2, 0, 1])
>>> torch.argsort (p1)
tensor([1, 2, 0])
>>> p2 = torch.tensor ([5, 2, 0, 1, 4, 3])
>>> torch.argsort (p2)
tensor([2, 3, 1, 5, 4, 0])
Best.
K. Frank