[Numpy-tickets] [NumPy] #453: coercion rules for boolean arrays are broken
NumPy
numpy-tickets@scipy....
Fri Feb 16 13:11:55 CST 2007
#453: coercion rules for boolean arrays are broken
------------------------+---------------------------------------------------
Reporter: chanley | Owner: somebody
Type: defect | Status: new
Priority: highest | Milestone:
Component: numpy.core | Version: devel
Severity: critical | Keywords:
------------------------+---------------------------------------------------
In Python boolean multiplication results in the following:
{{{
In [1]: True * 4096
Out[1]: 4096
}}}
NUMARRAY is consistent with what you get from Python:
{{{
In [2]: import numarray
In [3]: a = numarray.ones(10,type=numarray.Bool)
In [4]: print a
[1 1 1 1 1 1 1 1 1 1]
In [5]: a * 4096
Out[5]: array([4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096,
4096])
}}}
However, numpy gives the following results:
{{{
In [6]: import numpy
In [7]: b = numpy.ones(10,dtype=numpy.bool_)
In [8]: print b
[ True True True True True True True True True True]
In [9]: b * 4096
Out[9]: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int8)
}}}
The NUMPY coercion rules are not even self consistent. If you extract an
element from array b to get a rank zero array you get the same behavior as
Python:
{{{
In [10]: print b[0]
True
In [11]: b[0] * 4096
Out[11]: 4096
}}}
--
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/453>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list