[Numpy-discussion] Efficient array equivalent to cmp(x,y)
Kim Hansen
slaunger@gmail....
Thu Sep 17 15:33:24 CDT 2009
>
>
>
> 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 what I was looking for.
Cheers,
Kim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090917/5d443c80/attachment.html
More information about the NumPy-Discussion
mailing list