[英]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?
有没有更好的办法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.