[Numpy-discussion] Bug in loadtxt

Thomas Robitaille thomas.robitaille at gmail.com
Sat Aug 21 13:43:55 EDT 2010


Hi,

I am running into a precision issue with np.loadtxt. I have a data file 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)

I have submitted a bug report:

http://projects.scipy.org/numpy/ticket/1589

Cheers,

Tom


More information about the NumPy-Discussion mailing list