[Numpy-discussion] convert FORTRAN exponential format text to float

David Froger david.froger@gmail....
Wed Sep 29 09:45:57 CDT 2010


program write_txt

real(kind=8):: x

open(10,file='data.txt')

do i = 1,10
    x = i*2.
    write(10,fmt='(2(D12.3))') x,x**2
enddo

close(10)

end program write_txt



In [1]: x,y = loadtxt('data.txt',unpack=True)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/home/dfroger/tmp/<ipython console> in <module>()

/usr/lib/python2.5/site-packages/numpy/lib/io.pyc in loadtxt(fname, dtype,
comments, delimiter, converters, skiprows, usecols, unpack)
    350
    351         # Convert each value according to its column and store
--> 352         X.append(tuple([conv(val) for (conv, val) in zip(converters,
vals)]))
    353
    354     if len(dtype_types) > 1:

ValueError: invalid literal for float(): 0.200D+01


Maybe the the arguments 'converters' of loadtxt can help?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100929/037ea3a8/attachment.html 


More information about the NumPy-Discussion mailing list