首页 >> 知识 >> python:argsort(返回元素排序后的索引值)

python:argsort(返回元素排序后的索引值)

http://numpy.org/doc/stable/reference/generated/numpy.argsort.html   官方英文

http://www.osgeo.cn/numpy/reference/generated/numpy.argsort.html  官方中文

http://www.cnblogs.com/yyxf1413/p/6253995.html   浅述python中argsort()函数的用法

http://blog.csdn.net/maoersong/article/details/21875705   numpy中argsort函数用法(有升序、降序用法)

http://blog.csdn.net/u014745194/article/details/73496836   argsort()函数的总结(看这个,举的例子很清晰!!!)

 

argsort():将数组x中的元素从小到大排序,然后返回对应的索引值。

一维数组:

import numpy as np# 一维数组x = np.array([3, 1, 6, 2])y1 = np.argsort(x) #升序排列print(y1)y2 = np.argsort(-x) #降序排列print(y2)# 输出结果:[1 3 0 2][2 0 3 1]

 二维数组:

# 二维数组x = np.array([[0, 3, -1], [2, 5, 8]])y1 = np.argsort(x, axis=0) #按列排序print(y1)y2 = np.argsort(x, axis=1) #按行排序print(y2) # 输出结果:[[0 0 0] [1 1 1]][[2 0 1] [0 1 2]]

 

网站地图