[Numpy-discussion] where() on mac/pc return different things

James Battat jbattat at cfa.harvard.edu
Wed Jan 23 18:54:37 EST 2008


Robert,

Thanks for solving that puzzle!  I'll get our group on the same 1.0.x
numpy release.

Take care,
James

**************************
Harvard University
Dept. of Astronomy
60 Garden Street
MS-10
Cambridge, MA 02138
phone 617.496.5988
lab   617.495.3267
email jbattat at cfa.harvard.edu
web   http://www.cfa.harvard.edu/~jbattat
**************************


On Wed, 23 Jan 2008, Robert Kern wrote:

> James Battat wrote:
> > Hi,
> >
> > numpy.where() returns different things on my windowsXP machine than on my
> > collaborator's mac osx machine.
> >
> > For example, consider:
> >   >>> import numpy
> >   >>> a = numpy.array([1,2,3,4])
> >   >>> b = numpy.where( a > 2 )
> >
> > On WindowsXP (python 2.4.2, numpy 1.0.1), I get:
> >   >>> print b
> >   (array([2, 3]), )
> >   >>> print b[0]
> >   [2 3]
> >
> > While in OSX (python 2.4.3, numpy 0.9.6), he gets:
> >   >>> print b
> >   [2, 3]
> >   >>> print b[0]
> >   2
> >
> > This matters because we use where() to get indices to loop over.  On the
> > mac you can then loop through the b array:
> >
> > for item in b:
> >    if b > 5:
> >       print 'hi'
> >
> > But this approach fails on a pc because:
> >    if b > 5:
> >   >>> ValueError: The truth value of an array with more than one element
> >   >>> is ambiguous. Use a.any() or a.all()
> >
> >
> > I'd like to avoid having to do:
> >   if mac:
> >     b = numpy.where( a > 5)
> >   if pc:
> >     b = numpy.where( a > 5)[0]
> >
> > Has anybody else notice dealt with this?  Is this a mac/pc difference or a
> > numpy 1.01 vs. numpy 0.9.6 difference?
>
> The latter. Before the 1.0 release, we tried to make it clear that we were still
> experimenting with the APIs and that they might change up until 1.0 got released.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>   that is made terrible by our own mad attempt to interpret it as though it had
>   an underlying truth."
>    -- Umberto Eco
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list