简要说明
argsort(a, axis=-1, kind='quicksort', order=None)
按照kin关键字指定的排序方式,对原数组按照从小到大的顺序进行排序,得到一个新的数组,将该数组中每个元素在原数组中的索引值代替该元素得到
例子:
x = np.array(np.random.randint(1,100,6))
# x: array([15, 16, 18, 7, 83, 53])
y = np.argsort(x)
# 输出array([3, 0, 1, 2, 5, 4], dtype=int64)
y_1 = sorted(x)
# [7, 15, 16, 18, 53, 83]
解释
可以看出,7在x中的索引值为3,
15在x中的索引值为0,
16在x中的索引值为1
简单的等价表达式:
ls = []
x_1 = list(x)
for i in y_1:
ls.append(x.index(i))