Skip to content

loadtxt reads floats in as float32 instead of float64 under certain cicumstances (Trac #1589) #2185

@numpy-gitbot

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/1589 on 2010-08-21 by @astrofrog, assigned to unknown.

I have a file called data.txt with the following contents:

$ cat data.txt
-9.9999999961922814E-01
-9.9999999996192290E-01
-9.9999999999619227E-01
-9.9999999999961919E-01
-9.9999999999996192E-01
-9.9999999999999611E-01
-1.0000000000000000E+00

If I try and read this in using loadtxt, which should read numbers in using (64-bit) float by default, I get:

Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'2.0.0.dev8657'
>>> np.loadtxt('data.txt')
array([-1., -1., -1., -1., -1., -1., -1.])

If I now create a file called data2.txt with only the first line:

$ cat data2.txt
-9.9999999961922814E-01

loadtxt works correctly:

Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'2.0.0.dev8657'
>>> np.loadtxt('data2.txt')
array(-0.99999999961922814)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions