[Numpy-discussion] finding range of values below threshold in sorted array

Emmanuelle Gouillart emmanuelle.gouillart@normalesup....
Fri Aug 14 07:49:04 CDT 2009


ind = np.searchsorted(A, b)
values = A[:ind]



On Fri, Aug 14, 2009 at 02:27:23PM +0200, Mark Bakker wrote:
>    Hello List,
>    I am trying to find a quick way to do the following:
>    I have a *sorted* array of real numbers, say array A, sorted in ascending
>    order (but easy to store descending if that would help)
>    I want to find all numbers below a certain value, say b
>    Sure, I can do 
>    A < b
>    and I will get back a list with a bunch of True-s and then a bunch of
>    False's,
>    but all I need is the highest index for which A[i] < b, since A is sorted.
>    Does anybody know a quick way to do this? I need to do it a lot, so the
>    quicker the better.
>    Thanks,
>    Mark

> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list