我有一个这样的有序数组: numpy.array([1, 2, 5, 10, 25, 36, 66, 90, 121, 230, 333, 500])
假设我希望所有值都达到60(如果60不在,我想停在第一个值大于60),所以我想要[1, 2, 5, 10, 25, 36, 66]
.如果我使用numpy.where()
<= 60,它会在66之前停止.
我的解决方案
from numpy import *
x = array([1, 2, 5, 10, 25, 36, 66, 90, 121, 230, 333, 500])
print x[:where(x >= 60)[0][0]+1]
>>>[ 1 2 5 10 25 36 66]
Run Code Online (Sandbox Code Playgroud)