[Numpy-discussion] Find insertion point

Nikolaus Rath Nikolaus at rath.org
Tue Aug 17 14:17:35 EDT 2010


Lane Brooks <lane at brooks.nu> writes:
> On 08/17/2010 09:53 AM, Nikolaus Rath wrote:
>> Hello,
>>
>> I want to find the first i such that x[i]<  y and x[i+1]>= y. Is there
>> a way to do this without using a Python loop?
>>
>> I can't use np.searchsorted(), because my x array crosses y several
>> times.
>>
>>
>> Best,
>>
>>     -Nikolaus
>>
>
>
> i = numpy.nonzero(x>=y)[0][0]

I'm afraid that also fails the x = [1,2,3,2,3,4], y=3 test.


   -Nikolaus

-- 
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C



More information about the NumPy-Discussion mailing list