简体   繁体   English

如何查找值大于numpy中某个阈值的数组的索引?

[英]How to find the index of an array where the value is larger than some threshold in numpy?

In python (3.5.2) I have an increasing array of values, and I want to find the index at which the values become larger than some threshold. 在python(3.5.2)中,我拥有越来越多的值数组,并且我想找到值大于某个阈值的索引。

I tried the following code 我尝试了以下代码

f = [0.0, 9.7, 19.5, 29.2, 39.0, 48.8, 58.5, 68.3, 78.1, 87.8, 97.6, 107.4, 117.1, 126.9]
index = min(np.argwhere(f>100))

which yields an error 产生一个错误

TypeError: unorderable types: list() > int()

however, the expected outcome is index=11 , as f[11] is the first element of the array f to be larger than 100. 但是,预期结果为index=11 ,因为f[11]是数组f第一个大于100的元素。

How to fix this code? 如何修复此代码? Is there a better way? 有没有更好的办法?

This will do it: 这样做:

np.argwhere(np.array(f)>100).min()

Or: 要么:

np.argmax(np.array(f)>100)

Take note that argmax stops at first index that evaluates condition to True . 请注意, argmax在将条件评估为True第一个索引停止。

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

相关问题 最佳地从numpy数组中检索大于阈值的值 - Retrieve value larger than a threshold value from numpy array optimally 查找大于阈值的NumPy数组的第一个和最后一个元素 - find first and last element of a NumPy array larger than a threshold 查找数组位置大于阈值的位置,而下一个位置小于阈值(numpy) - Find array position greater than a threshold where the next position is less than the threshold (numpy) 在Numpy / PyTorch中快速查找值大于阈值的索引 - Quickly find indices that have values larger than a threshold in Numpy/PyTorch 如何获取排序数组的索引,其中前n个值的摘要大于某个值 - How to get the index of an sorted array where the summary of first n values larger than a certain value 如何从 numpy 数组中提取索引,其中连续匹配部分的大小大于某个最小值? - How can I extract indices from a numpy array where the size of a contiguous matching section is larger than some minimum? Python:numpy数组大于且小于值 - Python: numpy array larger and smaller than a value Numpy:获取索引大于值且条件为真的数组 - Numpy: get array where index greater than value and condition is true 在 numpy 数组中找到第一个较大的值 - Find the first larger value in numpy array 在 numpy 数组中查找第一次出现不是 X 或 Y 的某个值的索引 - Find the index of the first occurrence of some value that is not X or Y in a numpy array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM