I am wondering why Python truncates the numbers to integers whenever I assign floating point numbers to a numpy array:
import numpy as np
lst = np.asarray(list(range(10)))
print ("lst before assignment: ", lst)
lst[:4] = [0.3, 0.5, 10.6, 0.2];
print ("lst after assignment: ", lst)
output:
lst before assignment: [0 1 2 3 4 5 6 7 8 9]
lst after assignment: [ 0 0 10 0 4 5 6 7 8 9]
Why does it do this? Since you do not need to specify types in the language, I cannot understand why numpy would cast the floats to ints before assigning to the array (which contains integers).