[Numpy-discussion] strange conversion integer to float

Matthieu Brucher matthieu.brucher at gmail.com
Sat Dec 17 11:39:12 EST 2011


Hi,

If I remember correctly, float is a double (precision float). The precision
is more important in doubles (float64) than in usual floats (float32). And
20091231 can not be reprensented in 32bits floats.

Matthieu

2011/12/17 Alex van Houten <sparrow2867 at yahoo.com>

> Try this:
> $ python
> Python 2.7.1 (r271:86832, Apr 12 2011, 16:15:16)
> [GCC 4.6.0 20110331 (Red Hat 4.6.0-2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import numpy as np
> >>> np.__version__
> '1.5.1'
> >>> time=[]
> >>> time.append(20091231)
> >>> time_array=np.array(time,'f')
> >>> time_array
> array([ 20091232.], dtype=float32)
> 20091231--->20091232 Why?
> Note:
> >>> float(20091231)
> 20091231.0
> Thanks,
> Alex.
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>


-- 
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20111217/14623907/attachment.html>


More information about the NumPy-Discussion mailing list