我有需要N个最小值(指数)值在numpy的阵列 [英] I have need the N minimum (index) values in a numpy array

查看:118
本文介绍了我有需要N个最小值(指数)值在numpy的阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有它值多少多少的数组,我想找到十最小值指数法。在这个环节,他们计算的最大有效,<一个href=\"http://stackoverflow.com/questions/6910641/how-to-get-the-n-maximum-values-in-a-numpy-array\">How获得N个最大值在numpy的阵列?
然而,让我有重新发布的问题,我不能链接上尚未置评。

我不知道我需要改变,以达到最低,而不是最大值哪些索引。
这是他们的code

 在[1]:进口numpy的为NP在[2]:ARR = np.array([1,3,2,4,5])在[3]:arr.argsort()[ -  3:] [::  -  1]
出[3]:阵列([4,3,1])


解决方案

如果你调用

  arr.argsort()[3]

它会给你3个最小元素的索引。

 阵列([0,2,1],DTYPE = Int64的)

因此​​, N ,你应该叫

  arr.argsort():N]

Hi I have an array with X amount of values in it I would like to locate the indexs of the ten smallest values. In this link they calculated the maximum effectively, How to get the N maximum values in a numpy array? however I cant comment on links yet so I'm having to repost the question.

I'm not sure which indices i need to change to achieve the minimum and not the maximum values. This is their code

In [1]: import numpy as np

In [2]: arr = np.array([1, 3, 2, 4, 5])

In [3]: arr.argsort()[-3:][::-1]
Out[3]: array([4, 3, 1]) 

解决方案

If you call

arr.argsort()[:3]

It will give you the indices of the 3 smallest elements.

array([0, 2, 1], dtype=int64)

So, for n, you should call

arr.argsort()[:n]

这篇关于我有需要N个最小值(指数)值在numpy的阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆