python - Numpy array integer / float division -
this question has answer here:
- python augmented assignment issue 4 answers
i found following behaviour in python/numpy strange:
in [51]: = np.arange(10, 20) in [52]: = / 10.0 in [53]: out[53]: array([ 1. , 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9]) in [54]: = np.arange(10, 20) in [55]: /= 10.0 in [56]: out[56]: array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
i felt a=a/10.0
, a/=10.0
should return same result. inteded , documented somewhere?
the problem a /= 10.0
modifies array in place, , won't change the dtype of array, floats converted integers. on other hand a = / 10.0
created new array, , type can changed if new array being created.
from docs:
note assignments may result in changes if assigning higher types lower types (like floats ints) or exceptions (assigning complex floats or ints):
Comments
Post a Comment