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. 【XJOI-NOIP16提高模拟训练9】题解。

    http://www.hzxjhs.com:83/contest/55 说实话这次比赛真的很水..然而我只拿了140分,面壁反思. 第一题: 发现数位和sum最大就是9*18,k最大1000,那么su ...

  2. lintcode :First bad version 第一个错误的代码版本

    题目 第一个错误的代码版本 代码库的版本号是从 1 到 n 的整数.某一天,有人提交了错误版本的代码,因此造成自身及之后版本的代码在单元测试中均出错.请找出第一个错误的版本号. 你可以通过 isBad ...

  3. hibernate中openSession()跟getCurrentSession()方法之间的区别

    Hibernate openSession() 和 getCurrentSession的区别 getHiberanteTemplate .getCurrentSession和OpenSession 采 ...

  4. python_pycharm介绍1

    1. 常用设置 修改编程风格 File-Setting中,Editor下Colors&Fonts修改即可调整风格. 修改字体大小 pycharm默认字体太小,需调整些,Settings--&g ...

  5. Android:Android SDK Manager

    Android SDK Manager 包含:Tools(构建工具.编译工具.平台工具等) .各种版本SDK.Extras(安卓知识库和辅助工具) 每个SDK至少包含:1.SDK Plaform 2. ...

  6. http://www.cnblogs.com/AloneSword/p/3370462.html

    http://www.cnblogs.com/AloneSword/p/3370462.html

  7. Node 实现 AES 加密,结果输出为“byte”。

    Node 实现 AES 加密,结果输出为"byte". 最近做个需求,对接一个平台的接口,该平台采用 AES (Advanced Encryption Standard)加密算法, ...

  8. Android之开发杂记(三)

    一.popup 弹出框 在onCreate中创建时异常 Unable to add window -- token null is not valid; is your activity runnin ...

  9. Android 代码监控apk安装,卸载,替换

    public class GetBroadcast extends BroadcastReceiver { private static GetBroadcast mReceiver = new Ge ...

  10. JS身份证真实性校验(二)

    var Wi = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 ]; // 加权因子 var ValideCode = [ 1, 0 ...