>>> import numpy

>>> help(numpy.argsort)

Help on function argsort in module numpy.core.fromnumeric:

argsort(a, axis=-1, kind='quicksort', order=None)

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.

从中可以看出argsort函数返回的是数组值从小到大的索引值

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

#######################################

例1:

>>> x = np.array([3, 1, 2])

>>> np.argsort(x) #按升序排列

array([1, 2, 0])

>>> np.argsort(-x) #按降序排列

array([0, 2, 1])

>>> x[np.argsort(x)] #通过索引值排序后的数组

array([1, 2, 3])

>>> x[np.argsort(-x)]

array([3, 2, 1])

另一种方式实现按降序排序:

>>> a = x[np.argsort(x)]

>>> a

array([1, 2, 3])

>>> a[::-1]

array([3, 2, 1])

python中的argsort函数的更多相关文章

  1. python --- Python中的callable 函数

    python --- Python中的callable 函数 转自: http://archive.cnblogs.com/a/1798319/ Python中的callable 函数 callabl ...

  2. python中使用zip函数出现<zip object at 0x02A9E418>

    在Python中使用zip函数,出现<zip object at 0x02A9E418>错误的原因是,你是用的是python2点多的版本,python3.0对python做了改动 zip方 ...

  3. [转载]python中multiprocessing.pool函数介绍

    原文地址:http://blog.sina.com.cn/s/blog_5fa432b40101kwpi.html 作者:龙峰 摘自:http://hi.baidu.com/xjtukanif/blo ...

  4. Python 中的isinstance函数

    解释: Python 中的isinstance函数,isinstance是Python中的一个内建函数 语法: isinstance(object, classinfo) 如果参数object是cla ...

  5. Python中的map()函数和reduce()函数的用法

    Python中的map()函数和reduce()函数的用法 这篇文章主要介绍了Python中的map()函数和reduce()函数的用法,代码基于Python2.x版本,需要的朋友可以参考下   Py ...

  6. python中multiprocessing.pool函数介绍_正在拉磨_新浪博客

    python中multiprocessing.pool函数介绍_正在拉磨_新浪博客     python中multiprocessing.pool函数介绍    (2010-06-10 03:46:5 ...

  7. 举例详解Python中的split()函数的使用方法

    这篇文章主要介绍了举例详解Python中的split()函数的使用方法,split()函数的使用是Python学习当中的基础知识,通常用于将字符串切片并转换为列表,需要的朋友可以参考下   函数:sp ...

  8. python中的生成器函数是如何工作的?

    以下内容基于python3.4 1. python中的普通函数是怎么运行的? 当一个python函数在执行时,它会在相应的python栈帧上运行,栈帧表示程序运行时函数调用栈中的某一帧.想要获得某个函 ...

  9. python中的map()函数

    MapReduce的设计灵感来自于函数式编程,这里不打算提MapReduce,就拿python中的map()函数来学习一下. 文档中的介绍在这里: map(function, iterable, .. ...

随机推荐

  1. pythonl练习笔记——python线程的GIL

    python线程中的全局解释器锁GIL(Global Interpreter Lock) python-->支持多线程-->同步和互斥-->加锁-->解释器加锁-->解释 ...

  2. Python学习笔记015——汉字编码

    1 字符串的编码(encode)格式 GB2312   GBK   GB18030  UTF-8  ASCII 其中常用的编码格式有 国标系列:GB18030(GBK(GB2312)) (window ...

  3. 《JAVA与模式》之桥接模式

    桥接模式是一种结构型模式,它主要应对的是:由于实际的需要,某个类具有两个或两个以上的维度变化,如果只是用继承将无法实现这种需要,或者使得设计变得相当臃肿. 桥接模式的做法是把变化部分抽象出来,使变化部 ...

  4. ant批量运行Jmeter脚本遇到 Content is not allowed in prolog.问题及解决方案

    在执行 最后生成报告的 task 时,一直报下面这个错: TransformerException,  Content is not allowed in prolog. 解决方法:需要修改jmete ...

  5. C#实现foreach

    方法:一.继承既有的接口 如:CollectionBase.DictionaryBase class TestForeach: CollectionBase { public void Add(str ...

  6. DBA_实践指南系列6_Oracle Erp R12工作流通知邮件配置Email(案例)

    2013-12-06 Created By BaoXinjian

  7. AVL平衡二叉搜索树原理及各项操作编程实现

    C语言版 #include<stdio.h> #include "fatal.h" struct AvlNode; typedef struct AvlNode *Po ...

  8. js判断字符是否为空的方法

    js判断字符是否为空的方法: //判断字符是否为空的方法 function isEmpty(obj){ if(typeof obj == "undefined" || obj == ...

  9. opencv源代码之中的一个:cvboost.cpp

    我使用的是opencv2.4.9.安装后.我的cvboost..cpp文件的路径是........\opencv\sources\apps\haartraining\cvboost.cpp.研究源代码 ...

  10. iptables的4表5链(未完)

    iptables中共4张表:filter,nat,raw,mangle,其中默认表为filter如:iptables -A -p tcp -j ACCEPT 等价于 iptables -t filte ...