Re: [Numpy-discussion] boolean masks & lists

2007-11-06 Thread Travis E. Oliphant
John Hunter 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])
>   
The issues is how to determine what behavior is desired and how to 
manage that with all the possibilities.

Right now the rule is that only boolean arrays are treated as masks and 
integer arrays mean indexing.

Lists are always interpreted as integer indexing (except in certain 
special cases where the list has slice objects in it).Changing this 
to something like: lists are interpreted either as boolean or integer 
arrays, may be reasonable, but I don't see how we can change it until 
1.1 because the rule has already been specified and is consistent if not 
obvious in this simple case. 

The question is:  is anybody using boolean lists specifically according 
to the rule in place now?

-Travis







___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] boolean masks & lists

2007-11-06 Thread Timothy Hochberg
On Nov 6, 2007 7:22 AM, Lisandro Dalcin <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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@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@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
.  __
.   |-\
.
.  [EMAIL PROTECTED]
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] boolean masks & lists

2007-11-06 Thread John Hunter
On Nov 6, 2007 8:22 AM, Lisandro Dalcin <[EMAIL PROTECTED]> wrote:
> Mmm...
> It looks as it 'mask' is being inernally converted from
> [True, False, False, False, True]
> to
> [1, 0, 0, 0, 1]

Yep, clearly.  The question is: is this the desired behavior because
it leads to a "silent failure" for people who are expecting sequences
of booleans to behave like arrays of booleans.

JDH
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] boolean masks & lists

2007-11-06 Thread Lisandro Dalcin
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]


On 11/5/07, John Hunter <[EMAIL PROTECTED]> 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@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@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] boolean masks & lists

2007-11-05 Thread John Hunter
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@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion