Getting indices of ascending order of list

后端 未结 2 810
忘掉有多难
忘掉有多难 2021-01-16 13:33

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

2条回答
  •  一生所求
    2021-01-16 14:07

    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.

提交回复
热议问题