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 as a 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 : str or list of str, optional

When a is an array with fields defined, this argument specifies which fields to compare first, second, etc. A single field can be specified as a string, and not all fields need be specified, but unspecified fields will still be used, in the order in which they come up in the dtype, to break ties.

Returns:

index_array : ndarray, int

Array of indices that sort a along the specified axis. If a is one-dimensional, 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)  # sorts along first axis (down)
array([[0, 1],
[1, 0]])
>>> np.argsort(x, axis=1)  # sorts along last axis (across)
array([[0, 1],
[0, 1]])

Indices of the sorted elements of a N-dimensional array:

>>> ind = np.unravel_index(np.argsort(x, axis=None), x.shape)
>>> ind
(array([0, 1, 1, 0]), array([0, 0, 1, 1]))
>>> x[ind] # same as np.sort(x, axis=None)
array([0, 2, 2, 3])

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])

numpy.argsort详解的更多相关文章

  1. Python numpy.transpose 详解

    前言 看Python代码时,碰见 numpy.transpose 用于高维数组时挺让人费解,通过一番画图分析和代码验证,发现 transpose 用法还是很简单的. 正文 Numpy 文档 numpy ...

  2. 【python】详解numpy库与pandas库axis=0,axis= 1轴的用法

    对数据进行操作时,经常需要在横轴方向或者数轴方向对数据进行操作,这时需要设定参数axis的值: axis = 0 代表对横轴操作,也就是第0轴: axis = 1 代表对纵轴操作,也就是第1轴: nu ...

  3. numpy的文件存储.npy .npz 文件详解

    Numpy能够读写磁盘上的文本数据或二进制数据. 将数组以二进制格式保存到磁盘 np.load和np.save是读写磁盘数组数据的两个主要函数,默认情况下,数组是以未压缩的原始二进制格式保存在扩展名为 ...

  4. 非极大值抑制(NMS,Non-Maximum Suppression)的原理与代码详解

    1.NMS的原理 NMS(Non-Maximum Suppression)算法本质是搜索局部极大值,抑制非极大值元素.NMS就是需要根据score矩阵和region的坐标信息,从中找到置信度比较高的b ...

  5. Heapsort 堆排序算法详解(Java实现)

    Heapsort (堆排序)是最经典的排序算法之一,在google或者百度中搜一下可以搜到很多非常详细的解析.同样好的排序算法还有quicksort(快速排序)和merge sort(归并排序),选择 ...

  6. Raspiberry Camera详解+picamera库+Opencv控制

    使用树莓派的摄像头,将树莓派自身提供的picamera的API数据转换为Python Oencv可用图像数据: # import the necessary packages from picamer ...

  7. 基于双向BiLstm神经网络的中文分词详解及源码

    基于双向BiLstm神经网络的中文分词详解及源码 基于双向BiLstm神经网络的中文分词详解及源码 1 标注序列 2 训练网络 3 Viterbi算法求解最优路径 4 keras代码讲解 最后 源代码 ...

  8. 机器学习——KMeans聚类,KMeans原理,参数详解

    0.聚类 聚类就是对大量的未知标注的数据集,按数据的内在相似性将数据集划分为多个类别,使类别内的数据相似度较大而类别间的数据相似度较小,聚类属于无监督的学习方法. 1.内在相似性的度量 聚类是根据数据 ...

  9. 深度学习之卷积神经网络(CNN)详解与代码实现(一)

    卷积神经网络(CNN)详解与代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/10430073.html 目 ...

随机推荐

  1. VC++调用MSFlexGrid的SetRow方法,出现异常“Invalid Row Value”

    MSFlexGrid是微软提供的网格表格控件,SetRow方法用于设置当前焦点所在行.  C++ Code  12345   void CMSFlexGrid::SetRow(long nNewVal ...

  2. 存储过程打印超过8000的VARCHAR字符的问题

    DECLARE @info NVARCHAR(MAX) --SET @info to something big PRINT CAST(@info AS NTEXT) 这样就可以输出超过8000的字符 ...

  3. matplotlib使用GridSpec调整子图位置大小 (非对称的子图)

    用matplotlib.pyplot的subplots命令可以很方便的画对称的子图,但是如果要画非对称的子图(如下)就需要用GridSpec命令来控制子图的位置和大小: 而上图的结构可以用一下两种方式 ...

  4. php扩展yaf 按照配置

    Yaf,全称 Yet Another Framework,是一个C语言编写的PHP框架,是一个用PHP扩展形式提供的PHP开发框架, 相比于一般的PHP框架, 它更快. 它提供了Bootstrap, ...

  5. SpringMVC-----使用Maven创建Web项目

    1.创建一个Maven的project 2.不使用骨架,去掉勾 3.这里的Packing 选择 war的形式 由于packing是war包,那么下面也就多出了webapp的目录 4.由于我们的项目要使 ...

  6. Eclipse------导入项目后出现javax.servlet.jsp cannot be resolved to a type

    报错信息:javax.servlet.jsp cannot be resolved to a type 原因1: 这个错误可能是服务器自带的servlet库未导入的原因. 解决方法: 右键项目&quo ...

  7. SpringMVC由浅入深day01_5注解的处理器映射器和适配器

    5 注解的处理器映射器和适配器 在spring3.1之前使用org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandle ...

  8. GoF--服务定位器模式

    服务定位器模式(Service Locator Pattern)用在我们想使用 JNDI 查询定位各种服务的时候.考虑到为某个服务查找 JNDI 的代价很高,服务定位器模式充分利用了缓存技术.在首次请 ...

  9. RF根据单个/多个output文件重新生成log和report文件

    场景1:根据单个output文件重新生成log和report文件命令: rebot -d 日志和报告文件保存路径  output.xml文件 场景2:合并两个不同路径下的output文件并生成新的lo ...

  10. Selenium 选项卡管理

    什么是选项卡: from selenium import webdriver browser = webdriver.Chrome() browser.get("http://www.bai ...