You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
coercion rules for boolean arrays are broken (Trac #453) #1051
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
Activity
numpy-gitbot commentedon Oct 19, 2012
@teoliphant wrote on 2007-03-26
This should be fixed in SVN, r3601
The scalar/array coercion rule is that the type of the scalar will be ignored if the scalar is of the same kind or a lesser kind than the array.
The recognized kinds are (in order)
BOOL
POSINT
NEGINT
FLOAT
COMPLEX
OBJECT