Hi I'm trying to subtract a number for a entire column on a Numpy 2D array, and put the resultant values into the same column, but when the subtracted number is float and the array column is integer seems to Numpy convert the resut of the subtraction to int and then update it. Why this happened?
subtracting integer number
In [1]: a = np.array([[1,2],[2,3],[3,4]])
In [2]: a[:,1] - 1
Out[2]: array([1, 2, 3]) # <-- OK!
In [3]: a[:,1] = a[:,1] - 1 # <-- auto-update the array column
In [4]: a
Out[4]:
array([[1, 1],
[2, 2],
[3, 3]]) # <-- OK!
subtracting float number
In [1]: a = np.array([[1,2],[2,3],[3,4]])
In [2]: a[:,1] - 0.5
Out[2]: array([ 1.5, 2.5, 3.5]) # <-- seems to be ok
In [3]: a[:,1] = a[:,1] - 0.5 # <-- auto-update the array column
In [4]: a
Out[4]:
array([[1, 1],
[2, 2],
[3, 3]]) # <-- same result a[:,1] = a[:,1] - 1