[Numpy-discussion] Masking an array with another array
Wed Apr 22 19:18:05 CDT 2009
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."
On Wed, Apr 22, 2009 at 4:49 PM, Pierre GM <email@example.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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion