当前位置:网站首页>Numpy中排序操作partition,argpartition,sort,argsort
Numpy中排序操作partition,argpartition,sort,argsort
2022-07-06 20:00:00 【愚昧之山绝望之谷开悟之坡】
参考:
详细讲解:https://blog.csdn.net/m0_37192554/article/details/107459712
平时用惯了全排序np.sort,复杂度在到之间。如果待排序的数组特别大的话,时间开销不小。但通常特别大的数组排序不需要进行全排,可能仅仅需要取Top K。此时就可以使用部分排序,比如numpy.partition和numpy.argpartition。
partition函数的功能如下:给定一个array,将其中的元素重新整理使得第k位的元素刚好是全排序第k位的元素。所有比第k位元素小的元素都被放在它前面,所有比第k位元素大的元素都放在它后面。也就是说,这个第k位元素就将整个数组分成了两个部分,前面比它小,后面比它大。但是每个部分内部的元素并没有进行排序。
kth也可以是负数
表示数组a中第2大的元素即元素8位于排序完成数组b的倒数第2个位置上,即索引b[-2]处
当然,这有个什么用啊?用处之一就是如果我们有一个非常大的数组,假如我们想要找到其中最大的10个数,怎么办呢,我们可以用sort函数,然后排序完成后取出来,但是数组太大时这一方法比较耗时,所以我们可以采用partition函数,partition只对数组进行一遍排序,找到k位置的数即可,而对k位置左右的排序不关心,工作量少意味着其效率快
边栏推荐
- Kubernetes源码分析(二)----资源Resource
- Jerry's FM mode mono or stereo selection setting [chapter]
- Left value, right value
- Oracle connection pool is not used for a long time, and the connection fails
- Leetcode-02 (linked list question)
- The first symposium on "quantum computing + application of financial technology" was successfully held in Beijing
- Don't you know the relationship between JSP and servlet?
- Kubernetes source code analysis (II) -- resource
- [2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication
- Jericho is in non Bluetooth mode. Do not jump back to Bluetooth mode when connecting the mobile phone [chapter]
猜你喜欢
![[cpk-ra6m4 development board environment construction based on RT thread studio]](/img/08/9a847c73d6da6fc74d84af56897752.png)
[cpk-ra6m4 development board environment construction based on RT thread studio]

Es6中Promise的使用

Intelligent static presence detection scheme, 5.8G radar sensing technology, human presence inductive radar application

Use of promise in ES6

密码学系列之:在线证书状态协议OCSP详解

变量、流程控制与游标(MySQL)

Lavel PHP artisan automatically generates a complete set of model+migrate+controller commands

Construction of knowledge map of mall commodities

mos管实现主副电源自动切换电路,并且“零”压降,静态电流20uA

杰理之开启经典蓝牙 HID 手机的显示图标为键盘设置【篇】
随机推荐
cocos3——8. Implementation Guide for beginners
[cpk-ra6m4 development board environment construction based on RT thread studio]
Matlab Error (Matrix dimensions must agree)
Install redis from zero
input_delay
Hazel engine learning (V)
Intelligent static presence detection scheme, 5.8G radar sensing technology, human presence inductive radar application
Use of tensorboard
Jerry's broadcast has built-in flash prompt tone to control playback pause [chapter]
tensorboard的使用
QT Bluetooth: qbluetooth DeviceInfo
Unity uses maskablegraphic to draw a line with an arrow
Cglib agent in agent mode
Optimization of application startup speed
mos管实现主副电源自动切换电路,并且“零”压降,静态电流20uA
Leetcode-02 (linked list question)
Construction of knowledge map of mall commodities
上个厕所的功夫,就把定时任务的三种调度策略说得明明白白
How to find file accessed / created just feed minutes ago
腾讯云原生数据库TDSQL-C入选信通院《云原生产品目录》