[SciPy-user] newbie float representation question

Travis Oliphant oliphant.travis at ieee.org
Sun Dec 4 21:47:24 CST 2005


Alan G Isaac wrote:

>>>>import scipy
>>>>1/3.
>>>>        
>>>>
>0.33333333333333331
>  
>
>>>>scipy.array(1)/3.
>>>>        
>>>>
>0.33333333333333331
>  
>
>>>>scipy.array([1])/3.
>>>>        
>>>>
>array([ 0.33333334], dtype=float32)
>
>Why is the last representation "rounded up"?
>  
>

Because the result is a float32:

try scipy.array(1,dtype=float32)/3

This might be a problem with the scalar-vector coercion code.  Basically 
scalars do not determine coercion in array-scalar operations unless the 
kind changes (like in this case).  But,  I don't think a float32 array 
is correct here, I would expect a float64.   This is probably a bug.

-Travis



More information about the SciPy-user mailing list