[Numpy-discussion] bug in numpy.where?

Christopher Hanley chanley at gmail.com
Fri Jul 27 14:07:27 EDT 2012


On Fri, Jul 27, 2012 at 2:01 PM, Benjamin Root <ben.root at ou.edu> wrote:

>
>
> On Thu, Jul 26, 2012 at 2:33 PM, Phil Hodge <hodge at stsci.edu> wrote:
>
>> On a Linux machine:
>>
>>  > uname -srvop
>> Linux 2.6.18-308.8.2.el5 #1 SMP Tue May 29 11:54:17 EDT 2012 x86_64
>> GNU/Linux
>>
>> this example shows an apparent problem with the where function:
>>
>> Python 2.7.1 (r271:86832, Dec 21 2010, 11:19:43)
>> [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>  >>> import numpy as np
>>  >>> print np.__version__
>> 1.5.1
>>  >>> net = np.zeros(3, dtype='>f4')
>>  >>> net[1] = 0.00458849
>>  >>> net[2] = 0.605202
>>  >>> max_net = net.max()
>>  >>> test = np.where(net <= 0., max_net, net)
>>  >>> print test
>> [ -2.23910537e-35   4.58848989e-03   6.05202019e-01]
>>
>> When I specified the dtype for net as '>f8', test[0] was
>> 3.46244974e+68.  It worked as expected (i.e. test[0] should be 0.605202)
>> when I specified float(max_net) as the second argument to np.where.
>>
>> Phil
>>
>
> Confirmed with version 1.7.0.dev-470c857 on a CentOS6 64-bit machine.
> Strange indeed.
>
> Breaking it down further:
>
> >>> res = (net <= 0.)
> >>> print res
> [ True False False]
> >>> np.where(res, max_net, net)
> array([ -2.23910537e-35,   4.58848989e-03,   6.05202019e-01],
> dtype=float32)
>
> Very Strange...
>
> Ben Root
>

What if find really interesting is that -2.23910537e-35 is the byte swapped
version of 6.05202019e-01.

Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120727/0b9a694c/attachment.html>


More information about the NumPy-Discussion mailing list