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()函数是对数组中的元 ...
随机推荐
- Java多线程-线程的调度(守护线程)
本文转自http://www.cnblogs.com/linjiqin/p/3210004.html 感谢作者 守护线程与普通线程写法上基本没啥区别,调用线程对象的方法setDaemon(true), ...
- JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-002Table per concrete class with implicit polymorphism(@MappedSuperclass、@AttributeOverride)
一.结构 二.代码 1. package org.jpwh.model.inheritance.mappedsuperclass; import javax.persistence.MappedSup ...
- Mysql笔记——触发器简单实例
首先贴上触发器语法吧: CREATE TRIGGER <触发器名称> –触发器必须有名字,最多64个字符,可能后面会附有分隔符.它和MySQL中其他对象的命名方式基本相象. { BEFOR ...
- 296. Best Meeting Point
题目: A group of two or more people wants to meet and minimize the total travel distance. You are give ...
- 295. Find Median from Data Stream
题目: Median is the middle value in an ordered integer list. If the size of the list is even, there is ...
- Objective-C:三种文件导入的方式以及atomic和nonatomic的区别
一.三种文件导入的方式比较: 类的前项声明@class.import.include: 1.采用@class 类名的方式,它会告诉编译器有这么一个类,目前不需要知道它内部的实例变量和方法是如何定义 ...
- 《c程序设计语言》读书笔记--大于8 的字符串输出
#include <stdio.h> #define MAXLINE 100 #define MAX 8 int getline(char line[],int maxline); voi ...
- git提交代码步骤
01:首先git status一下查看当前目录下修改的文件,当然编译生成的文件也在其中,我们只看自己修改的: 02:git add ****** //(文件名) 将上述查找到自己修改的文件添加到git ...
- win7下制作ubuntu系统安装启动盘和U盘安装ubuntu全过程
在我搞坏了两个系统之后,一切都得从头开始了,这回好了,电脑就是一台裸机了.没办法,重新下win7吧.这个要先做一个win7的启动盘,然后再安装,只能说我技术不行,没能把win7搞定.让大神给装的win ...
- 如何理解JAVA的跨平台特性
1.java的跨平台,是指java在运行时是凌驾于os之上,是在jvm中运行的,跟os没有直接联系. 2.java跨平台主要是由java的编译方式决定的,因为java是通过jvm先编译再执行,它编译的 ...