简体   繁体   English

带有科学符号EXY的python

[英]python with scientific notation EXY

So I am writing the columns of an array to a file and the file is to be used by a program that is space sensitive, so it has to be exactly the right way like this: 因此,我正在将数组的列写入文件,并且该文件将由对空间敏感的程序使用,因此它必须像这样完全正确:

*DEFINE_CURVE_TRIM 
$     TCID    TCTYPE      TFLG      TDIR     TCTOL  TOLN/IGB     NSEED 
      1111         1        -1         0     0.001
 7.50000E01 , 0.00000E00
 7.49906E01 , 1.18995E00
 7.49622E01 , 2.37960E00

I am working with some floats with alot of decimals, so I am rounding them to have the same number of decimals, but python notation is E+01 and it has to be E01 我正在使用一些带有很多小数的浮点数,因此我将它们取整为具有相同的小数位数,但是python表示法是E + 01,它必须是E01

udskrift = open('DEFINE_CURVE_TRIM_FULL','w')
udskrift.write('*DEFINE_CURVE_TRIM\n$     TCID    TCTYPE      TFLG      TDIR     TCTOL  TOLN/IGB     NSEED\n      1111         1        -1         0     0.001\n')
for entry in polar_koordinator:
    udskrift.write(" %.5E , %.5E\n" % (entry[2], entry[3]))

output is 输出是

*DEFINE_CURVE_TRIM
$     TCID    TCTYPE      TFLG      TDIR     TCTOL  TOLN/IGB     NSEED
      1111         1        -1         0     0.001
 8.00976E+01 , 0.00000E+00
 8.01050E+01 , 1.25839E+00

So any pointers on how to remove the '+' so it becomes E01? 那么关于如何删除“ +”使其变为E01的任何指示? I would hate to have to reopen the file and remove them 我讨厌必须重新打开文件并删除它们

One easy way out is to write 一种简单的解决方法是编写

udskrift.write((" %.5E , %.5E\n" % (entry[2], entry[3])).replace('E+', 'E'))

but that does not seem pythonic. 但这似乎不是pythonic。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM