<small id='0ezUy'></small><noframes id='0ezUy'>

<legend id='0ezUy'><style id='0ezUy'><dir id='0ezUy'><q id='0ezUy'></q></dir></style></legend>
        <bdo id='0ezUy'></bdo><ul id='0ezUy'></ul>
    1. <tfoot id='0ezUy'></tfoot>

        <i id='0ezUy'><tr id='0ezUy'><dt id='0ezUy'><q id='0ezUy'><span id='0ezUy'><b id='0ezUy'><form id='0ezUy'><ins id='0ezUy'></ins><ul id='0ezUy'></ul><sub id='0ezUy'></sub></form><legend id='0ezUy'></legend><bdo id='0ezUy'><pre id='0ezUy'><center id='0ezUy'></center></pre></bdo></b><th id='0ezUy'></th></span></q></dt></tr></i><div id='0ezUy'><tfoot id='0ezUy'></tfoot><dl id='0ezUy'><fieldset id='0ezUy'></fieldset></dl></div>

      1. 使用 Python 读取 FORTRAN 格式的数字

        时间:2023-09-12

        <small id='yPvoQ'></small><noframes id='yPvoQ'>

        <i id='yPvoQ'><tr id='yPvoQ'><dt id='yPvoQ'><q id='yPvoQ'><span id='yPvoQ'><b id='yPvoQ'><form id='yPvoQ'><ins id='yPvoQ'></ins><ul id='yPvoQ'></ul><sub id='yPvoQ'></sub></form><legend id='yPvoQ'></legend><bdo id='yPvoQ'><pre id='yPvoQ'><center id='yPvoQ'></center></pre></bdo></b><th id='yPvoQ'></th></span></q></dt></tr></i><div id='yPvoQ'><tfoot id='yPvoQ'></tfoot><dl id='yPvoQ'><fieldset id='yPvoQ'></fieldset></dl></div>

              <legend id='yPvoQ'><style id='yPvoQ'><dir id='yPvoQ'><q id='yPvoQ'></q></dir></style></legend>
                <tbody id='yPvoQ'></tbody>
              <tfoot id='yPvoQ'></tfoot>

                • <bdo id='yPvoQ'></bdo><ul id='yPvoQ'></ul>
                • 本文介绍了使用 Python 读取 FORTRAN 格式的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我必须读取一个数据文件,其中包含以(非常)旧的 FORTRAN 样式格式化的数字.文件的一行如下所示:

                  I have to read a data file that contains numbers formatted with (very) old FORTRAN style. A line of the file looks like this:

                   4.500000+1 1.894719-3 4.600000+1 8.196721-3 4.700000+1 2.869539-3
                  

                  文件(或其中的大部分)以固定宽度格式包含这些数字.在 Python 中读取这些数字的问题在于这些数字中没有 E.看看会发生什么:

                  The file (or large portion of it) contains these numbers in a fixed width format. The trouble with reading these numbers in Python is that there is no E in these numbers. Watch what happens:

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

                  我可以编写一个解析器来读取这个,但想知道这是否已经完成.这是一种旧的 FORTRAN 格式,所以我想也许有人已经弄清楚了.有人知道图书馆可以读取这样的数字吗?

                  I can write a parser to read this, but wanted to know if this has already be done. This is an old FORTRAN format so I thought perhaps someone had already figured it out. Does anyone know of a library to read numbers like this?

                  推荐答案

                  这应该可以:

                  In [47]: strs="4.500000+1 1.894719-3 4.600000+1 8.196721-3 4.700000+1 2.869539-3"
                  
                  In [48]: [float(x.replace("+","e+").replace("-","e-")) for x in strs.split()]
                  
                  Out[48]: [45.0, 0.001894719, 46.0, 0.008196721, 47.0, 0.002869539]
                  

                  这篇关于使用 Python 读取 FORTRAN 格式的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:读取fortran未格式化文件时记录标记不一致 下一篇:zgeev() LAPACK 的结果不正确/不一致

                  相关文章

                  最新文章

                  • <bdo id='D5OWx'></bdo><ul id='D5OWx'></ul>
                • <small id='D5OWx'></small><noframes id='D5OWx'>

                  1. <tfoot id='D5OWx'></tfoot>
                    1. <i id='D5OWx'><tr id='D5OWx'><dt id='D5OWx'><q id='D5OWx'><span id='D5OWx'><b id='D5OWx'><form id='D5OWx'><ins id='D5OWx'></ins><ul id='D5OWx'></ul><sub id='D5OWx'></sub></form><legend id='D5OWx'></legend><bdo id='D5OWx'><pre id='D5OWx'><center id='D5OWx'></center></pre></bdo></b><th id='D5OWx'></th></span></q></dt></tr></i><div id='D5OWx'><tfoot id='D5OWx'></tfoot><dl id='D5OWx'><fieldset id='D5OWx'></fieldset></dl></div>
                      <legend id='D5OWx'><style id='D5OWx'><dir id='D5OWx'><q id='D5OWx'></q></dir></style></legend>