Get original indices of a sorted Numpy array

后端 未结 2 1932
鱼传尺愫
鱼传尺愫 2020-12-08 09:30

I have an array of distances a = np.array([20.5 ,5.3 ,60.7 ,3.0 ], \'double\') and I need the indices of the sorted array (for example [3, 1, 0, 2]

2条回答
  •  不思量自难忘°
    2020-12-08 10:08

    Yes, there's the x = numpy.argsort(a) function or x = numpy.ndarray.argsort(a) method. It does exactly what you're asking for. You can also call argsort as a method on an ndarray object like so: a.argsort().

    Here's a link to the documentation: http://docs.scipy.org/doc/numpy/reference/generated/numpy.argsort.html#numpy.argsort

提交回复
热议问题