[Numpy-discussion] Bug in loadtxt

josef.pktd@gmai... josef.pktd@gmai...
Sat Aug 21 12:52:08 CDT 2010


On Sat, Aug 21, 2010 at 1:43 PM, Thomas Robitaille
<thomas.robitaille@gmail.com> wrote:
> 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


are you sure this is not just a print precision problem?

>>> a =np.array([-9.9999999961922814E-01,
-9.9999999996192290E-01,
-9.9999999999619227E-01,
-9.9999999999961919E-01,
-9.9999999999996192E-01,
-9.9999999999999611E-01,
-1.0000000000000000E+00])
>>> a
array([-1., -1., -1., -1., -1., -1., -1.])
>>> a[0]
-0.99999999961922814
>>> a[:1]
array([-1.])

Josef

>
> Cheers,
>
> Tom
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list