numpy.argsort

numpy.argsort(aaxis=-1kind='quicksort'order=None)[source]

Returns the indices that would sort an array.

Perform an indirect sort along the given axis using the algorithm specified by the kind keyword. It returns an array of indices of the same shape asa that index data along the given axis in sorted order.

Parameters:

a : array_like

Array to sort.

axis : int or None, optional

Axis along which to sort. The default is -1 (the last axis). If None, the flattened array is used.

kind : {‘quicksort’, ‘mergesort’, ‘heapsort’}, optional

Sorting algorithm.

order : list, optional

When a is an array with fields defined, this argument specifies which fields to compare first, second, etc. Not all fields need be specified.

Returns:

index_array : ndarray, int

Array of indices that sort a along the specified axis. In other words, a[index_array] yields a sorted a.

See also

sort
Describes sorting algorithms used.
lexsort
Indirect stable sort with multiple keys.
ndarray.sort
Inplace sort.
argpartition
Indirect partial sort.

Notes

See sort for notes on the different sorting algorithms.

As of NumPy 1.4.0 argsort works with real/complex arrays containing nan values. The enhanced sort order is documented in sort.

Examples

One dimensional array:

>>>

>>> x = np.array([3, 1, 2])
>>> np.argsort(x)
array([1, 2, 0])

Two-dimensional array:

>>>

>>> x = np.array([[0, 3], [2, 2]])
>>> x
array([[0, 3],
[2, 2]])
>>>

>>> np.argsort(x, axis=0)
array([[0, 1],
[1, 0]])
>>>

>>> np.argsort(x, axis=1)
array([[0, 1],
[0, 1]])

Sorting with keys:

>>>

>>> x = np.array([(1, 0), (0, 1)], dtype=[('x', '<i4'), ('y', '<i4')])
>>> x
array([(1, 0), (0, 1)],
dtype=[('x', '<i4'), ('y', '<i4')])
>>>

>>> np.argsort(x, order=('x','y'))
array([1, 0])
>>>

>>> np.argsort(x, order=('y','x'))
array([0, 1])

python numpy argsort函数用法的更多相关文章

  1. python numpy sum函数用法

    numpy.sum numpy.sum(a, axis=None, dtype=None, out=None, keepdims=False)[source] Sum of array element ...

  2. Python Numpy shape 基础用法(转自他人的博客,如涉及到侵权,请联系我)

    Python Numpy shape 基础用法 shape函数是numpy.core.fromnumeric中的函数,它的功能是读取矩阵的长度,比如shape[0]就是读取矩阵第一维度的长度.它的输入 ...

  3. 【313】python 中 print 函数用法总结

    参考:python 中 print 函数用法总结 参考:Python print() 函数(菜鸟教程) 参考:Python 3 print 函数用法总结 目录: 字符串和数值类型 变量 格式化输出 p ...

  4. Python 3 print 函数用法总结

    Python 3 print 函数用法总结 1. 输出字符串和数字 print("runoob")    # 输出字符串 runoob print(100)            ...

  5. 细说Python的lambda函数用法,建议收藏

    细说Python的lambda函数用法,建议收藏 在Python中有两种函数,一种是def定义的函数,另一种是lambda函数,也就是大家常说的匿名函数.今天我就和大家聊聊lambda函数,在Pyth ...

  6. python format格式化函数用法

    python format格式化函数用法 原文 Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能. 基本语法是通过 {} 和 : 来代替以前 ...

  7. 浅述python中argsort()函数的用法

    由于想使用python用训练好的caffemodel来对很多图片进行批处理分类,学习过程中,碰到了argsort函数,因此去查了相关文献,也自己在python环境下进行了测试,大概了解了其相关的用处, ...

  8. numpy中argsort函数用法

    在Python中使用help帮助 >>> import numpy >>> help(numpy.argsort) Help on function argsort ...

  9. 关于python中argsort()函数的使用

    在实现<机器学习实战>中kNN代码时遇到需要将计算好的距离进行排序,即可使用argsort()函数,在此依据个人理解对该函数进行简单的介绍. 总的来说,argsort()函数是对数组中的元 ...

随机推荐

  1. (一)初探HTML!

    想自己动手做一个个人网站,因此,最近在自学PHP,主要看韩顺平老师的教学视频..将自己学习的点点滴滴记录在博客园,希望数月之后,自己可以熟练的运用PHP,也希望各位PHP高手们给予指点,不胜感激!! ...

  2. eclipse引入tomcat

    1.默认大家的tomcat都已经安装好了,这里打开eclipse,选择windows,下面的属性(preference). 2.进入到属性配置页,选择server  --   runtime Envi ...

  3. BFS+贪心 HDOJ 5335 Walk Out

    题目传送门 /* 题意:求从(1, 1)走到(n, m)的二进制路径值最小 BFS+贪心:按照标程的作法,首先BFS搜索所有相邻0的位置,直到1出现.接下去从最靠近终点的1开始, 每一次走一步,不走回 ...

  4. JSTL标签库中fmt标签,日期,数字的格式化

    首先介绍日期的格式化:(不要嫌多哦) JSTL格式化日期(本地化) 类似于数字和货币格式化,本地化环境还会影响生成日期和时间的方式. <%@ page pageEncoding="UT ...

  5. servlet中中文乱码问题

    在web项目中经常回碰到中文乱码的问题,特此整理一下,有不足的地方,希望大家纠正. 1从前台往后台传数据,.以get方式发送请求,发送的参数不乱,但是后台接收到参数乱码 在Tomcat的server. ...

  6. Java-马士兵设计模式学习笔记-观察者模式-AWT简单例子

    1.AWT简单例子 TestFrame.java import java.awt.Button; import java.awt.Frame; import java.awt.event.Action ...

  7. JLINK V8 升级5.12E 在MDK5.20不变砖

    转载:只是用了新的固件,步骤跟原子提供的方法 是一模一样的.这边也把步骤写了上来. 使用 SAM-PROG 更新 JLINK 固件一 :安装软件 安装 Install AT91-ISP v1.13.e ...

  8. 解密ThreadLocal

    原文:http://qifuguang.me/2015/09/02/%5BJava%E5%B9%B6%E5%8F%91%E5%8C%85%E5%AD%A6%E4%B9%A0%E4%B8%83%5D%E ...

  9. iOS:Git分布式版本控制器系统

    Git的使用 1.Git简介: Git是一个开源的分布式版本控制系统.与SVN.CVS相比 分布式    不需要中心仓库 Git的版本号都是生成的一个哈希值,比如:bbaf6fb5060b4875b1 ...

  10. java.lang.ClassNotFoundException: org.springframework.context.event.GenericApplicationListener ----good

    Caused by: java.lang.NoClassDefFoundError: org/springframework/context/event/GenericApplicationListe ...