简体   繁体   English

在Python数组中查找最小值

[英]Finding Minimum in Python Arrays

I have two arrays say x = [110, 10, 1000 ....] and y = ['adas', 'asdasqe', 'ae1e' ....] 我有两个数组,分别是x = [110, 10, 1000 ....] y = ['adas', 'asdasqe', 'ae1e' ....] x = [110, 10, 1000 ....]y = ['adas', 'asdasqe', 'ae1e' ....]

Both of these arrays are of the same length. 这两个数组都具有相同的长度。 My problem is that or printing the 10 values of y such that the corresponding values of x are the 10 largest. 我的问题是或打印y的10个值,以使x的相应值最大为10个。

In an average test case, x and y are 4000-5000 in length. 在平均测试案例中, xy的长度为4000-5000。 So speed is of the essence. 因此,速度至关重要。 Could you tell me a way of doing this using some of the inbuilt functions of python so that the operation is as fast as possible. 你能告诉我一个使用python的一些内置函数做到这一点的方法,以便操作尽可能快。

If you want the ten top elements from a list of several thousands, you can try heapq : 如果你想要几千个列表中的十个顶级元素,你可以尝试heapq

import heapq

heapq.nlargest(10, zip(x, y))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM