I want to get an index for the inverse mapping of np.sort
In other words, if I have a code
x=[[4,3],[2,3],[4,2]]
ind1=np.lexsort((x[:,1],x[:,0]))
y=x[ind1] #y=[[2,3],[4,2],[4,3]]
then I want an index such that
y[ind]
returns the original function x. Is there any way to get this index?
Use np.argsort
on ind1
:
idx = np.argsort(ind1)
y[idx]
# array([[4, 3],
# [2, 3],
# [4, 2]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With