I have an ordered array like this: numpy.array([1, 2, 5, 10, 25, 36, 66, 90, 121, 230, 333, 500])
Suppose I want all values up to 60 (if 60 isn't in, i want to stop at the first value greater than 60), so I want [1, 2, 5, 10, 25, 36, 66]
. If I use numpy.where()
with <= 60, it stops before 66.
My solution
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]