[Numpy-discussion] Masking an array with another array

Gökhan SEVER gokhansever@gmail....
Thu Apr 23 00:24:35 CDT 2009


Ahaa,,

Thanks Gaël. That method is more elegance than the previous inputs, and the
simplest of all.

Although one line of "import this" says:

There should be one-- and preferably only one --obvious way to do it.

I always find many different ways of implementing ideas in Python world.

Gökhan


On Thu, Apr 23, 2009 at 12:16 AM, Gael Varoquaux <
gael.varoquaux@normalesup.org> wrote:

> On Wed, Apr 22, 2009 at 04:21:05PM -0500, Gökhan SEVER wrote:
> >    Could you please give me some hints about how to mask an array using
> >    another arrays like in the following example.
>
> >    In [14]: a = arange(5)
>
> >    In [15]: a
> >    Out[15]: array([0, 1, 2, 3, 4])
>
> >    and my secondary array is "b"
>
> >    In [16]: b = array([2,3])
>
> >    What I want to do is to mask a with b values and get an array of:
>
> >    array([False, False, True, True,  False], dtype=bool)
>
> This is an operation on 'sets': you are testing if members of a are 'in'
> b. Generally, set operations on arrays can be found in
> numpy.lib.arraysetops. I believe what you are interested in is
> setmember1d.
>
> HTH,
>
> Gaël
> _______________________________________________
> 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/20090423/e0237b03/attachment.html 


More information about the Numpy-discussion mailing list