Why during slicing assignment in numpy array decimals disappears?

arrays, numpy, python, slice, variable-assignment

Solution

No, it is not a bug. From docs:

Note that assignments may result in changes if assigning higher types to lower types (like floats to ints) or even exceptions (assigning complex to floats or ints)

Problem

``` from numpy import * a=array([0.,0.001,0.002]) b=array([[1,11],[2,22],[3,33]]) b[:,1]=a print b ``` I expected as a result: ``` array([[ 1. , 0. ],[ 2. , 0.001 ],[ 3. , 0.002 ]]) ``` But I got: ``` array([[ 1 , 0 ], [ 2 , 0 ] , [ 3 , 0 ]]) ``` To obtain desired result I had to type: ``` from numpy import * a=array([0.,0.001,0.002]) b=array([[1,11],[2,22],[3,33]]) b=b.astype(float) b[:,1]=a print b ``` Is it a bug? Shouldn't assignment automatically make numpy array a float type?

Original source