将fortran双精度格式读入python [英] Reading fortran double precision format into python

查看:169
本文介绍了将fortran双精度格式读入python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图读取一个Fortran双精度数字,如1.2345D + 02到python,但是我收到以下错误:

I am trying to read a Fortran double-precision number like 1.2345D+02 into python, but I got the following error:

>>> float('1.2345D+02')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): 1.2345D+02

按照建议在使用D代替E的Python科学符号,我试过numpy但我也得到相同的错误:

By following the advice on Python scientific notation using D instead of E, I tried numpy but I also get the same error:

import numpy
>>> numpy.float("1.2345D+02")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): 1.2345D+02

是否有解决方案在Python中阅读这些双精度数字,而不用将'D'更改为'E'?

Is there a solution in Python to read those double precision numbers without just changing the 'D' to 'E'?

编辑:我替换了字符串上的错误语法。但是我仍然收到错误。

I replaced a bad syntax on the strings. But still I get errors.

推荐答案

float(str.replace(D E))

请注意,numpy支持fortran符号: numpy.float(1.2345D +02)

Please note, numpy DOES support fortran notation: numpy.float("1.2345D+02").

你似乎有一些更深层次的目的,可能会说明它会有所帮助。

You seem to have some deeper purpose, perhaps shedding light on it would help.

这篇关于将fortran双精度格式读入python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆