浅析python中numpy包中的argsort函数的使用


Posted in Python onAugust 30, 2018

概述

argsort()函数在模块numpy.core.fromnumeric中。

在python中排序数组,或者获取排序顺序的时候,我们常常使用numpy包的argsort函数来完成。

如下图所示,是使用python获取到数组中的排序的顺序。

data=numpy.array([1,2,3,4,5])
datasort=numpy.argsort(data)
datasort
Out[39]: array([0, 1, 2, 3, 4], dtype=int64)
data
Out[40]: array([1, 2, 3, 4, 5])
datasort1=data.argsort()
datasort1
Out[42]: array([0, 1, 2, 3, 4], dtype=int64)

我们也可以通过help(numpy.argsort)来查看使用方法

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

如果想要通过argsort实现排序可以使用切片实现

data1=numpy.array([1,3,4,56,2,0])
datasort=data1[data1.argsort()]
datasort
Out[48]: array([ 0, 1, 2, 3, 4, 56])

PS:NumPy 中argsort函数

排序函数,返回array类型

argsort函数返回的是数组值从小到大的元素的索引值

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
inX = np.array([1,2,-1,3,4,7,8])
print inX
print inX.argsort()

浅析python中numpy包中的argsort函数的使用

总结

以上所述是小编给大家介绍的python中numpy包中的argsort函数的使用,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

Python 相关文章推荐
Django的session中对于用户验证的支持
Jul 23 Python
Windows下anaconda安装第三方包的方法小结(tensorflow、gensim为例)
Apr 05 Python
pandas修改DataFrame列名的方法
Apr 08 Python
Python八大常见排序算法定义、实现及时间消耗效率分析
Apr 27 Python
详解Python 数据库的Connection、Cursor两大对象
Jun 25 Python
Python SQL查询并生成json文件操作示例
Aug 17 Python
一文带你了解Python中的字符串是什么
Nov 20 Python
python实例化对象的具体方法
Jun 17 Python
python对一个数向上取整的实例方法
Jun 18 Python
python获取系统内存占用信息的实例方法
Jul 17 Python
python学习笔记之多进程
Aug 06 Python
python 实现的IP 存活扫描脚本
Dec 10 Python
浅析python3中的os.path.dirname(__file__)的使用
Aug 30 #Python
python语音识别实践之百度语音API
Aug 30 #Python
python调用百度语音识别实现大音频文件语音识别功能
Aug 30 #Python
python的中异常处理机制
Aug 30 #Python
python调用百度REST API实现语音识别
Aug 30 #Python
python调用百度语音REST API
Aug 30 #Python
python调用百度语音识别api
Aug 30 #Python
You might like
Thinkphp事务操作实例(推荐)
2017/04/01 PHP
laravel 解决paginate查询多个字段报错的问题
2019/10/22 PHP
jQuery拖动图片删除示例
2013/05/10 Javascript
jQuery实现图片放大预览实现原理及代码
2013/09/12 Javascript
JavaScript打印网页指定区域的例子
2014/05/03 Javascript
AngularJS使用带属性值的ng-app指令实现自定义模块自动加载的方法
2017/01/04 Javascript
微信小程序 WebSocket详解及应用
2017/01/21 Javascript
jQuery插件FusionCharts绘制ScrollColumn2D图效果示例【附demo源码下载】
2017/03/22 jQuery
jQuery Tree Multiselect使用详解
2017/05/02 jQuery
详解如何构建Angular项目目录结构
2017/07/13 Javascript
vue element实现表格合并行数据
2020/11/30 Vue.js
python使用str & repr转换字符串
2016/10/13 Python
python常见排序算法基础教程
2017/04/13 Python
python使用 HTMLTestRunner.py生成测试报告
2017/10/20 Python
2018年Python值得关注的开源库、工具和开发者(总结篇)
2018/01/04 Python
Python英文文章词频统计(14份剑桥真题词频统计)
2019/10/13 Python
使用 Python 写一个简易的抽奖程序
2019/12/08 Python
Pytorch使用MNIST数据集实现CGAN和生成指定的数字方式
2020/01/10 Python
Python3连接Mysql8.0遇到的问题及处理步骤
2020/02/17 Python
python安装sklearn模块的方法详解
2020/11/28 Python
基于python的opencv图像处理实现对斑马线的检测示例
2020/11/29 Python
html5 桌面提醒:Notifycations应用介绍
2012/11/27 HTML / CSS
Jogun Shop中文官网:韩国知名时尚男装网站
2016/10/12 全球购物
公共汽车、火车和飞机票的通用在线预订和销售平台:INFOBUS
2019/11/30 全球购物
澳大利亚在线奢侈品时尚零售平台:Azura Runway
2021/01/13 全球购物
秋季婚礼证婚词
2014/01/11 职场文书
20岁生日感言
2014/01/13 职场文书
简历中自我评价怎么写
2014/02/12 职场文书
不打扫卫生检讨书
2014/02/12 职场文书
高三毕业寄语
2014/04/10 职场文书
医学专业大学生求职信
2014/07/12 职场文书
党的群众路线教育实践活动批评与自我批评范文
2014/10/16 职场文书
投资意向协议书
2015/01/29 职场文书
学历证明范文
2015/06/16 职场文书
Java spring定时任务详解
2021/10/05 Java/Android
Java 常见的限流算法详细分析并实现
2022/04/07 Java/Android