[Numpy-discussion] a==b for numpy arrays

Keith Goodman kwgoodman at gmail.com
Mon Dec 11 17:48:41 CST 2006


On 12/11/06, Steve Lianoglou <lists.steve at arachnedesign.net> wrote:
> > It's not relevant to the point of this discussion all that much, but:
> >
> >> a[a < 0] = 0
> >> a[less(a, 0)] = 0
> >
> > Instead I've been doing something like:
> >
> > a[where(a < 0)] = 0
> >
> > I didn't realized you could do it the other way. Is there a
> > difference somewhere between the two, or are they interchangeable?
>
> Ah ... I see, w/o the where returns a boolean array. I reckon that's
> actually better to use than the where clause for cases like this
> since (for one) it'll take up less memory than arrays of ints.

These are different:

a[a[:,0] >0, :]

a[where(a[:,0].A >0)[0],:]

I think it would be great if the former gave the same result as the latter.


More information about the Numpy-discussion mailing list