Tuesday, May 26, 2015

"Consistency" Bug in NumPy?

I am sorry for doing some of these in succession, but a colleague of mine (Gordon Erlebacher) alerted me to this frustrating bug/feature in numpy.

>>> import numpy as np

>>> a = np.array([1,2,3])
>>> a = a * 0.3
>>> print a    # integers are converted to float
[ 0.3  0.6  0.9]

>>> a = np.array([1,2,3])
>>> a *= 0.3  # integers are not converted to float
>>> print a
[0 0 0]

I tested these on numpy 1.8.2, Python 2.7.6.

No comments:

Post a Comment