[Numpy-discussion] Masking an array with another array

Gökhan SEVER gokhansever@gmail....
Wed Apr 22 19:18:05 CDT 2009


Yes Pierre,

I like this one line of elegances in Python a lot. I was thinking that the
answer lies in somewhere in masked array operations, but I proved wrong.

Thanks for your input on this small riddle.

Here is another way of doing that. (That's what I thought of initially and
what Matthias Michler responded on matplotlib mailing list.)

mask = zeros(len(a), dtype=bool)
for index in xrange(len(a)):        # run through array a
   if a[index] in b:
       mask[index] = True


Ending with a quote about Pythonicness :)

"...that something is Pythonic when it has a sense of quality,
simplicity, clarity and elegance about it."


Gökhan


On Wed, Apr 22, 2009 at 4:49 PM, Pierre GM <pgmdevlist@gmail.com> wrote:

>
> On Apr 22, 2009, at 5:21 PM, Gökhan SEVER wrote:
>
> > Hello,
> >
> > Could you please give me some hints about how to mask an array using
> > another arrays like in the following example.
>
> What about that ?
> numpy.logical_or.reduce([a==i for i in b])
>
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090422/5958215b/attachment-0001.html 


More information about the Numpy-discussion mailing list