python numpy argsort函数用法
numpy.argsort
- numpy.argsort(a, axis=-1, kind='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函数用法的更多相关文章
- python numpy sum函数用法
numpy.sum numpy.sum(a, axis=None, dtype=None, out=None, keepdims=False)[source] Sum of array element ...
- Python Numpy shape 基础用法(转自他人的博客,如涉及到侵权,请联系我)
Python Numpy shape 基础用法 shape函数是numpy.core.fromnumeric中的函数,它的功能是读取矩阵的长度,比如shape[0]就是读取矩阵第一维度的长度.它的输入 ...
- 【313】python 中 print 函数用法总结
参考:python 中 print 函数用法总结 参考:Python print() 函数(菜鸟教程) 参考:Python 3 print 函数用法总结 目录: 字符串和数值类型 变量 格式化输出 p ...
- Python 3 print 函数用法总结
Python 3 print 函数用法总结 1. 输出字符串和数字 print("runoob") # 输出字符串 runoob print(100) ...
- 细说Python的lambda函数用法,建议收藏
细说Python的lambda函数用法,建议收藏 在Python中有两种函数,一种是def定义的函数,另一种是lambda函数,也就是大家常说的匿名函数.今天我就和大家聊聊lambda函数,在Pyth ...
- python format格式化函数用法
python format格式化函数用法 原文 Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能. 基本语法是通过 {} 和 : 来代替以前 ...
- 浅述python中argsort()函数的用法
由于想使用python用训练好的caffemodel来对很多图片进行批处理分类,学习过程中,碰到了argsort函数,因此去查了相关文献,也自己在python环境下进行了测试,大概了解了其相关的用处, ...
- numpy中argsort函数用法
在Python中使用help帮助 >>> import numpy >>> help(numpy.argsort) Help on function argsort ...
- 关于python中argsort()函数的使用
在实现<机器学习实战>中kNN代码时遇到需要将计算好的距离进行排序,即可使用argsort()函数,在此依据个人理解对该函数进行简单的介绍. 总的来说,argsort()函数是对数组中的元 ...
随机推荐
- 利用securecrt在linux与windows之间传输文件
SecureCRT这款SSH客户端软件同时具备了终端仿真器和文件传输功能.比ftp命令方便多了,而且服务器不用再开FTP服务了.rz,sz是便是Linux/Unix同Windows进行ZModem文件 ...
- How to say "no"?
How to say "no"?7招教你如何拒绝别人 Do you have a hard time saying no to others? Do you say “y ...
- Java-马士兵设计模式学习笔记-观察者模式-读取properties文件改成单例模式
一.概述 1.目标:读取properties文件改成单例模式 二.代码 1.Test.java class WakenUpEvent{ private long time; private Strin ...
- WordPress主题制作教程7:引用其他php的方法
在模板中包含指定的模板文件,指定{slug}和{name}就可以包含文件{slug}-{name}.php,如果没有这个文件则包含{slug}.php文件 <?php get_template_ ...
- .NET中使用OleDb读取Excel
在.NET中可以用OleDb(Object linking and embeding DataBase)来访问Excel using System; using System.Data; using ...
- Java日期转换SimpleDateFormat格式大全(转)
24小时制时间显示: public class Datetime { public static void main(String args[]){ java.util.Date current=ne ...
- java基础篇---I/O技术
java基础篇---I/O技术 对于任何程序设计语言而言,输入输出(I/O)系统都是比较复杂的而且还是比较核心的.在java.io.包中提供了相关的API. java中流的概念划分 流的方向: 输 ...
- USACO Section 2.3: Zero Sum
这题我做得比较麻烦,网上有个比较简单的程序. /* ID: yingzho1 LANG: C++ TASK: zerosum */ #include <iostream> #include ...
- C# 字符串计算表达式
C# 字符串计算表达式 string str="4+4+2.1"; 要的效果: double sum=4+4+2.1: 方案一: 动态计算表达式: 1 public class ...
- 在LINUX上创建GIT服务器【转】
转自:http://blog.csdn.net/xiongmc/article/details/9176785 如果使用git的人数较少,可以使用下面的步骤快速部署一个git服务器环境. 1. Cli ...