Swap array positions / values

Is there a way to perform this operation more efficiently?

   sort1 = torch.sort(abs(u.grad))[1]
   srtcoe= u.grad.clone()
   for li in range(z.lrsize[lr]):
      for pi in range(z.lrsize[lr-1]):
         srtcoe[li][sort1[li][pi]] = pi /z.lrsize[pr]