Re: [Numpy-discussion] Efficient array equivalent to cmp(x,y)

2009-09-17 Thread Kim Hansen
> > > > In [1]: a = np.array([0, 2, 4, 1, 3, 0, 3, 4, 0, 1]) > > In [2]: lim = 2 > > In [3]: np.sign(a - lim) > Out[3]: array([-1, 0, 1, -1, 1, -1, 1, 1, -1, -1]) > Dooh. Facepalm. I should have thought of that myself! Only one intermediate array needs to be created then. Thank you. That was

Re: [Numpy-discussion] Efficient array equivalent to cmp(x,y)

2009-09-17 Thread Kim Hansen
> > > > If there are no NaNs, you only need to make 2 masks by using ones > instead of empty. Not elegent but a little faster. > Good point! Thanks. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy

Re: [Numpy-discussion] Efficient array equivalent to cmp(x,y)

2009-09-17 Thread Robert Kern
[Please pardon the piggybacking. I didn't get the original.] On Thu, Sep 17, 2009 at 15:19, Keith Goodman wrote: > On Thu, Sep 17, 2009 at 1:13 PM, Kim Hansen wrote: >> Hi, >> >> Is there an array-like function equivalent with the builtin method for the >> Python single-valued comparison cmp(x,y

Re: [Numpy-discussion] Efficient array equivalent to cmp(x,y)

2009-09-17 Thread Keith Goodman
On Thu, Sep 17, 2009 at 1:13 PM, Kim Hansen wrote: > Hi, > > Is there an array-like function equivalent with the builtin method for the > Python single-valued comparison cmp(x,y)? > > What I would like is a cmp(a, lim), where a is an ndarray and lim is a > single value, and then I need an array ba

[Numpy-discussion] Efficient array equivalent to cmp(x,y)

2009-09-17 Thread Kim Hansen
Hi, Is there an array-like function equivalent with the builtin method for the Python single-valued comparison cmp(x,y)? What I would like is a cmp(a, lim), where a is an ndarray and lim is a single value, and then I need an array back of a's shape giving the elementwise comparison array([cmp(a[0