当前位置:网站首页>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位置左右的排序不关心,工作量少意味着其效率快
边栏推荐
- Centerx: open centernet in the way of socialism with Chinese characteristics
- SSL证书错误怎么办?浏览器常见SSL证书报错解决办法
- [cpk-ra6m4 development board environment construction based on RT thread studio]
- Codeforces round 264 (Div. 2) C gargari and Bishop [violence]
- When you go to the toilet, you can clearly explain the three Scheduling Strategies of scheduled tasks
- 杰理之发射端在接收端关机之后假死机【篇】
- oracle连接池长时间不使用连接失效问题
- Redis introduction complete tutorial: client case analysis
- 2022 information security engineer examination outline
- 体会设计细节
猜你喜欢
![Jerry's broadcast has built-in flash prompt tone to control playback pause [chapter]](/img/8c/e8f7e667e4762a4815e97c36a2759f.png)
Jerry's broadcast has built-in flash prompt tone to control playback pause [chapter]

左程云 递归+动态规划

How to analyze fans' interests?

input_delay
![[tools] basic concept of database and MySQL installation](/img/9c/626e42097050517a13a2ce7cdab1bb.jpg)
[tools] basic concept of database and MySQL installation

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

Left value, right value

存储过程与函数(MySQL)
![Jericho is in non Bluetooth mode. Do not jump back to Bluetooth mode when connecting the mobile phone [chapter]](/img/ce/baa4acb1b4bfc19ccf8982e1e320b2.png)
Jericho is in non Bluetooth mode. Do not jump back to Bluetooth mode when connecting the mobile phone [chapter]

上个厕所的功夫,就把定时任务的三种调度策略说得明明白白
随机推荐
tensorboard的使用
你知道电子招标最突出的5大好处有哪些吗?
杰理之关于 DAC 输出功率问题【篇】
Analysis of USB network card sending and receiving data
[tools] basic concept of database and MySQL installation
[swift] learning notes (I) -- familiar with basic data types, coding styles, tuples, propositions
DOMContentLoaded和window.onload
Redis introduction complete tutorial: replication principle
input_ delay
How does C language (string) delete a specified character in a string?
[cpk-ra6m4 development board environment construction based on RT thread studio]
Construction of knowledge map of mall commodities
Household appliance industry under the "retail is king": what is the industry consensus?
Utilisation de la promesse dans es6
Codeforces round 264 (Div. 2) C gargari and Bishop [violence]
Jerry's transmitter crashed after the receiver shut down [chapter]
新标杆!智慧化社会治理
sshd[12282]: fatal: matching cipher is not supported: [email protected] [preauth]
安装 torch 0.4.1
cocos3——8. Implementation Guide for beginners