numpy.argsort以随机顺序给出结果

RKM*_*RKM 0 python sorting numpy

我试图简单地使用排序数组或列表numpy.argsort().出于某种原因,它以随机顺序给我结果:

import numpy

unsorted_list = [1.19021287, 1.19021287, 1.15190644, 1.12193492, 1.19021287, 1.25190644]
sorted_list = numpy.argsort(unsorted_list)
print sorted_list
array([3, 2, 0, 1, 4, 5])
Run Code Online (Sandbox Code Playgroud)

它应该回来 array([0, 1, 4, 3, 5, 4])

Jim*_*ard 5

那该怎么numpy.argsort办?

numpy.argsort(a, axis=-1, kind='quicksort', order=None)

返回对数组进行排序的索引.

使用kind关键字指定的算法沿给定轴执行间接排序.它a以排序顺序返回与给定轴上的索引数据形状相同的索引数组.

因此它为您提供了对数组进行排序的索引,从数组中的最小值到最大值.对于您给定的数组,这些是:

[3, 2, 0, 1, 4, 5]
Run Code Online (Sandbox Code Playgroud)

对应的值:

3 -> 1.12193492
2 -> 1.15190644
0 -> 1.19021287
1 -> 1.19021287
4 -> 1.19021287
5 -> 1.25190644
Run Code Online (Sandbox Code Playgroud)

因此,0例如添加尾部会导致返回以下索引:

[6 3 2 0 1 4 5]
Run Code Online (Sandbox Code Playgroud)