[Numpy-discussion] boolean masks & lists

Timothy Hochberg tim.hochberg at ieee.org
Tue Nov 6 09:33:19 EST 2007


On Nov 6, 2007 7:22 AM, Lisandro Dalcin <dalcinl at gmail.com> wrote:

> Mmm...
> It looks as it 'mask' is being inernally converted from
> [True, False, False, False, True]
> to
> [1, 0, 0, 0, 1]
>
> so your are finally getting
>
> x[1], x[0], x[0], x[0], x[1]


That would be my guess as well. And, it looks wrong to me. Given that
array(mask) gives you the boolean mask, there's every expectation to expect
the the list and array cases should be the same. I would file a bug report.


>
>
>
> On 11/5/07, John Hunter <jdh2358 at gmail.com> wrote:
> > A colleague of mine just asked for help with a pesky bug that turned
> > out to be caused by his use of a list of booleans rather than an array
> > of booleans as his logical indexing mask.  I assume this is a feature
> > and not a bug, but it certainly surprised him:
> >
> > In [58]: mask = [True, False, False, False, True]
> >
> > In [59]: maska = n.array(mask, n.bool)
> >
> > In [60]: x = arange(5)
> >
> > In [61]: x[mask]
> > Out[61]: array([1, 0, 0, 0, 1])
> >
> > In [62]: x[maska]
> > Out[62]: array([0, 4])
> > _______________________________________________
> > Numpy-discussion mailing list
> > Numpy-discussion at scipy.org
> > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> >
>
>
> --
> Lisandro Dalcín
> ---------------
> Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
> Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
> Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
> PTLC - Güemes 3450, (3000) Santa Fe, Argentina
> Tel/Fax: +54-(0)342-451.1594
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
.  __
.   |-\
.
.  tim.hochberg at ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20071106/9c62a7e5/attachment.html>


More information about the NumPy-Discussion mailing list