argsort for a multidimensional ndarray

后端 未结 4 460
深忆病人
深忆病人 2020-12-03 06:21

I\'m trying to get the indices to sort a multidimensional array by the last axis, e.g.

>>> a = np.array([[3,1,2],[8,9,2]])

And I\'

4条回答
  •  孤街浪徒
    2020-12-03 06:47

    I found the answer here, with someone having the same problem. They key is just cheating the indexing to work properly...

    >>> a[np.arange(np.shape(a)[0])[:,np.newaxis], np.argsort(a)]
    array([[1, 2, 3],
           [2, 8, 9]])
    

提交回复
热议问题