python - 在 Python 中查找数组的最低 5 个数字的索引

标签 python

如何找出哪些索引属于数组的最低 x(例如,5)个数字?

[10.18398473, 9.95722384, 9.41220631, 9.42846614, 9.7300549 , 9.69949144, 9.86997862, 10.28299122, 9.97274071, 10. 6676>

另外,如何直接找到排序后(从低到高)最低的x个数?

最佳答案

现有的答案很好,但如果您使用 numpy,这里是解决方案:

mylist = np.array([10.18398473, 9.95722384, 9.41220631, 9.42846614, 9.7300549 , 9.69949144, 9.86997862, 10.28299122, 9.97274071, 10.08966867, 9.7])
x = 5
lowestx = np.argsort(mylist)[:x]
#array([ 2,  3,  5, 10,  4])

关于python - 在 Python 中查找数组的最低 5 个数字的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15488102/

相关文章:

python - 如何使用 Python 找到图像右下角的图像(像素?)值?

python - 子图中直方图的动画

python - 互斥关键字参数的优雅模式?

python - 不支持在 include() 中指定命名空间而不提供 app_name

Python For 循环、函数问题

python - Networkx 情节 : Make edges stay out of the nodes

python - 在 Python 2.7 中读取大型 lz4 压缩 JSON 数据集

python - devpi 和 pypi 服务器的区别

python - 用于获取维基百科编辑内容的 API

python - 无法使用反向名称解析路径的 URL 字符串