Re: [Numpy-discussion] Find insertion point

2010-08-17 Thread Nikolaus Rath
Warren Weckesser writes: > 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. >> > > In [34]: np.where((x[:

Re: [Numpy-discussion] Find insertion point

2010-08-17 Thread Nikolaus Rath
Lane Brooks 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. >> >> >> Be

Re: [Numpy-discussion] Find insertion point

2010-08-17 Thread Nikolaus Rath
Alan G Isaac 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) >

Re: [Numpy-discussion] Find insertion point

2010-08-17 Thread Warren Weckesser
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 > > Here's one way: In [32]: x

Re: [Numpy-discussion] Find insertion point

2010-08-17 Thread Lane Brooks
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 = num

Re: [Numpy-discussion] Find insertion point

2010-08-17 Thread Alan G Isaac
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 f

[Numpy-discussion] Find insertion point

2010-08-17 Thread Nikolaus Rath
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 -- »Time flies like an arrow, fruit flies like a Banana.« PGP fingerp