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 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
sortfor notes on the different sorting algorithms.As of NumPy 1.4.0
argsortworks with real/complex arrays containing nan values. The enhanced sort order is documented insort.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详解的更多相关文章
- Python numpy.transpose 详解
前言 看Python代码时,碰见 numpy.transpose 用于高维数组时挺让人费解,通过一番画图分析和代码验证,发现 transpose 用法还是很简单的. 正文 Numpy 文档 numpy ...
- 【python】详解numpy库与pandas库axis=0,axis= 1轴的用法
对数据进行操作时,经常需要在横轴方向或者数轴方向对数据进行操作,这时需要设定参数axis的值: axis = 0 代表对横轴操作,也就是第0轴: axis = 1 代表对纵轴操作,也就是第1轴: nu ...
- numpy的文件存储.npy .npz 文件详解
Numpy能够读写磁盘上的文本数据或二进制数据. 将数组以二进制格式保存到磁盘 np.load和np.save是读写磁盘数组数据的两个主要函数,默认情况下,数组是以未压缩的原始二进制格式保存在扩展名为 ...
- 非极大值抑制(NMS,Non-Maximum Suppression)的原理与代码详解
1.NMS的原理 NMS(Non-Maximum Suppression)算法本质是搜索局部极大值,抑制非极大值元素.NMS就是需要根据score矩阵和region的坐标信息,从中找到置信度比较高的b ...
- Heapsort 堆排序算法详解(Java实现)
Heapsort (堆排序)是最经典的排序算法之一,在google或者百度中搜一下可以搜到很多非常详细的解析.同样好的排序算法还有quicksort(快速排序)和merge sort(归并排序),选择 ...
- Raspiberry Camera详解+picamera库+Opencv控制
使用树莓派的摄像头,将树莓派自身提供的picamera的API数据转换为Python Oencv可用图像数据: # import the necessary packages from picamer ...
- 基于双向BiLstm神经网络的中文分词详解及源码
基于双向BiLstm神经网络的中文分词详解及源码 基于双向BiLstm神经网络的中文分词详解及源码 1 标注序列 2 训练网络 3 Viterbi算法求解最优路径 4 keras代码讲解 最后 源代码 ...
- 机器学习——KMeans聚类,KMeans原理,参数详解
0.聚类 聚类就是对大量的未知标注的数据集,按数据的内在相似性将数据集划分为多个类别,使类别内的数据相似度较大而类别间的数据相似度较小,聚类属于无监督的学习方法. 1.内在相似性的度量 聚类是根据数据 ...
- 深度学习之卷积神经网络(CNN)详解与代码实现(一)
卷积神经网络(CNN)详解与代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/10430073.html 目 ...
随机推荐
- 图像添加到ABBYY 文档有什么方法
ABBYY FineReader 12作为一款功能全面的OCR图文识别软件,我们自是可以在其中将图像添加到FineReader文档中去,且添加在文档尾部,否则将会创建一个新的FineReader文档. ...
- SDK Manager.exe和AVD Manager.exe缺失,Android SDK Tools在检查java环境时卡住了,未响应卡死!
之前安装Android Studio的时候根据提示安装了Android SDK,但是发现目录下没有SDK Manager.exe和AVD Manager.exe,导致SDK的一些操作很不方便! 不知道 ...
- 使用Matplotlib画图系列(一)
实现一个最简单的plot函数调用: import matplotlib.pyplot as plt y=pp.DS.Transac_open # 设置y轴数据,以数组形式提供 x=len(y) # 设 ...
- NPOI把Excel导入到数据库
二,把Excel中的数据导入到数据库的具体步骤: protected void Button1_Click(object sender, EventArgs e) { ...
- yii 前端js动态添加验证规则
在使用 activeForm 生成表单及验证时,默认是按照 model 里的 rules 生成js验证,model 验证在加载完页面后生效,不可修改,如果需要扩展.动态验证,需要使用js来配合 直接上 ...
- Windows Server 2008 R2 WSUS服务器的详细配置和部署
WSUS客户端配置 我们要让客户端计算机能够通过WSUS服务器下载更新程序,而这个设置在域环境和单台PC是的方法不同,这里介绍一下本地计算机如何进行设置. 1.开始--运行--输入gpedit.msc ...
- SpringBoot(十二)-- 整合Redis
1.pom依赖 <!-- 添加redis支持 --> <dependency> <groupId>org.springframework.boot</grou ...
- [Ubuntu] apt 添加第三方库
1. 方法一:直接在 /etc/apt/sources.list 添加第三方库. $ sudo vi /etc/apt/sources.list 在其中添加: deb http://archive.s ...
- jinja语法
<!--base.html--> <!DOCTYPE html> <html lang="en"> <head> <!--ht ...
- lua总则
lua官方英文文档:http://www.lua.org/manual/5.2/ lua中国开发者网址:http://bbs.luaer.cn/ <lua程序设计(第二版)>(闭合函数和闭 ...