>>> 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. spring-integration-kafka

    1.pom.xml配置 <dependency> <groupId>org.springframework.integration</groupId> <ar ...

  2. python学习笔记—— 多进程中的 孤儿进程和僵尸进程

    1 基本概述 1.1 孤儿进程和僵尸进程 父进程创建子进程后,较为理想状态是子进程结束,父进程回收子进程并释放子进程占有的资源:而实际上,父子进程是异步过程,两者谁先结束是无顺的,一般可以通过父进程调 ...

  3. 使用Xcode 查看objective-C的汇编代码

    Xcode自带将某一个源文件转化成汇编的功能.如图: 汇编的部分代码例如以下: # Assembly output for assemble.c # Generated at 2:29:34 下午 o ...

  4. nginx实战六

    Nginx错误日志 https://coding.net/u/aminglinux/p/nginx/git/blob/master/log/error.md Nginx错误日志平时不用太关注,但是一旦 ...

  5. Python radians() 函数

    描述 radians() 方法将角度转换为弧度. 语法 以下是 radians() 方法的语法: import math math.radians(x) 注意:radians()是不能直接访问的,需要 ...

  6. Python2 unichr() 函数

    描述 unichr() 函数 和 chr()函数功能基本一样, 只不过是返回 unicode 的字符. 语法 以下是 unichr() 方法的语法: unichr(i) 参数 i -- 可以是10进制 ...

  7. win7 64 安装scikit-learn

    1. scikit-learn简单介绍 scikit-learn是一个基于NumPy.SciPy.Matplotlib的开源机器学习工具包.採用Python语言编写.主要涵盖分类. 回归和聚类等算法, ...

  8. C# 获取方法内参数名称

    public partial class Main : Form { public Main() { foreach(var parameter in typeof(Main).GetMethod(& ...

  9. Ext.net中Combobox如何绑定数据库中的值-通用方法

    今天在项目中再次碰到了问题,就是Combobox中的值如果是直接绑定很简单.简单添加项就行了.代码如下: <ext:ComboBox ID=" /> </Items> ...

  10. SQL中的LIKE中用参数化查询

    今天终于学会怎么在like中用参数化查询啦..哈哈..再也不用担心sql注入了...