I know that this question has been asked a hundred times, but the answer always seems to be \"use numpy\'s argsort\". But either I am misinterpreting what most people are as
The reason why you are not getting the 'right,' or expected, answer is because you are asking the wrong question!
What you are after is the element rank after sort while Numpy's argsort() returns the sorted index list, as documented!. These are not the same thing (as you found out ;) )!
The argsoft()
is basically converting your list to a sorted list of indices.
l = [4, 2, 1, 3]
First it gets index of each element in the list so new list becomes:
indexed=[0, 1, 2, 3]
Then it sorts the indexed list according to the items in the original list. As 4:0 , 2:1 , 1:2 and 3:3
where : means "corresponds to".
Sorting the original list we get
l=[1, 2, 3, 4]
And placing values of each corresponding index of old list
new=[2,1,3,0]
So basically it sorts the indices of a list according to the original list. This is as far as i understood. Sorry if i am wrong.