Numpy lexicographic ordering

后端 未结 2 462
無奈伤痛
無奈伤痛 2021-01-21 19:02

I\'d like to lexicographically sort the following array a (get index positions), but, I\'m having problems understanding the numpy results:

>>>         


        
相关标签:
2条回答
  • 2021-01-21 19:36

    The order of significance for keys is opposite to what you expected. In order to get expected result just flip the matrix upside down

    >>> np.lexsort(np.flipud(a))
    array([1, 4, 0, 2, 5, 3])
    
    0 讨论(0)
  • 2021-01-21 20:00

    np.lexsort gives you the index of the columns in lexicographic order, however the order it considers is such that the last element in the column has priority over the previous one and so on. That's why in your example column 5 comes before column 1.

    [2,0,2] < [1,1,2] because 2 = 2 and 0 < 1.

    0 讨论(0)
提交回复
热议问题