[Numpy-discussion] use of boolean index array returns byteswapped values

Christopher Hanley chanley at stsci.edu
Wed May 10 09:28:00 EDT 2006


When using a big-endian array on a little-endian OS, the use of a 
boolean array as an index array causes the resulting array to have 
byteswapped values.

Example code is below:

In [14]: a = numpy.array([1,2,3,4,5,6,7,8,9],'>f8')

In [15]: a
Out[15]: array([ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.])

In [16]: x = numpy.where( (a>2) & (a<6) )

In [17]: x
Out[17]: (array([2, 3, 4]),)

In [18]: a[x]
Out[18]: array([ 3.,  4.,  5.])

In [19]: y = ( (a>2) & (a<6) )

In [20]: y
Out[20]: array([False, False, True, True, True, False, False, False, 
False], dtype=bool)

In [21]: a[y]
Out[21]: array([  1.04346664e-320,   2.05531309e-320,   2.56123631e-320])

This bug was originally discovered by Erin Sheldon while testing pyfits.

I have submitted this bug report on the Trac site.


Chris




More information about the NumPy-Discussion mailing list