Sorry that my question may not clear enough and confuse many guys,it is described clearly and there is solution here:https://github.com/numpy/numpy/issues/8757
Given a list a
as:
a = [9, 3, 5]
I need the corresponding indices just as:
a_indices = [2, 0, 1]
But when I'm using the method from How can I save the original index after sorting a list?, the output is:
a_indices = [1, 2, 0]
What I need is similar to this:
>>> a = [4, 2, 3, 1, 4]
>>> b = sorted(enumerate(a), key=lambda i: i[1])
[(3, 1), (1, 2), (2, 3), (0, 4), (4, 4)]
The output above is correct but when I assign a
as below, the output is unexpected:
>>> a = [9, 3, 5]
>>> b = sorted(enumerate(a), key=lambda i: i[1])
>>> b
[(1, 3), (2, 5), (0, 9)]
The expected output is:
[(2, 3), (0, 5), (1, 9)]
I am confused by the sorting function and anyone could help to explain it to me?