[Numpy-discussion] Find insertion point

Nikolaus Rath Nikolaus@rath....
Tue Aug 17 13:15:24 CDT 2010


Alan G Isaac <alan.isaac@gmail.com> writes:
> On 8/17/2010 11:53 AM, Nikolaus Rath wrote:
>> 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?
>
>
> argmax? (to get i+1):
>          >>> d = np.linspace(0,10,101)
>          >>> x = np.sin(d)
>          >>> np.argmax(x>=0.5)
>          6

Not working for e.g. x = [4,3,2,3,4,5] and y=3.5.


Best,

   -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