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

David Froger david.froger@gmail....
Wed Sep 29 09:54:30 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]: def expDtofloat(s):
   ...:     return float(s.replace('D','E'))
   ...:

In [2]: x,y =
loadtxt('data.txt',unpack=True,converters={0:expDtofloat,1:expDtofloat})



Not really better than re.sub() ...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100929/87d54a06/attachment.html 


More information about the NumPy-Discussion mailing list