Strange behavior with numpy arrays. Can't add and store float array to int array

So ... I'm confused. It's always like that? I wasted an hour trying to find who the hell is restoring my array after I added the floating point array.

>>> import numpy as np
>>> a = np.array([1,2])
>>> a
array([1, 2])
>>> a += [0.1, 0.1]
>>> a
array([1, 2])
>>> a += np.array([0.1, 0.1])
>>> a
array([1, 2])
>>> a += np.array([0.1, 0.1])
>>> a
array([1, 2])
>>> a = a + [0.1, 0.1]
>>> a
array([ 1.1,  2.1])
>>> a = np.array([1,2]).astype(float)
>>> a += [0.1,0.2]
>>> a
array([ 1.1,  2.2])

      

EDIT: Well, it was completely unexpected. My life will never be the same, and now I will start creating lots of floating point arrays.

+3


source to share





All Articles