使用Python,我有两个大的(同样长的)文件,其中的数字除以空格:
0.11158E-13 0.11195E-13 0.11233E-13 …#file1
0.11010E-13 0.11070E-13 0.11117E-13 …#file2
那里 …
看起来您的文件各有一行。因此,获取每个文件中数字的最简单方法是只读取文件的整个内容,删除任何不需要的字符,然后拆分分隔浮点值的空白。拆分空间会给你一个列表 strings ,然后你可以强迫 floats 。此时,您应该有两个浮点值列表,即使用组合时的浮点值 zip 和 map 执行除法运算的功能。以下是一个例子:
strings
floats
zip
map
with open('ex1.idl') as f1, open('ex2.idl') as f2: with open('ex3.txt', 'w') as f3: f1 = map(float, f1.read().strip().split()) f2 = map(float, f2.read().strip().split()) for result in map(lambda v: v[0]/v[1], zip(f1, f2)): # This writes the results all in one line # If you wanted to write them in multiple lines, # then you would need replace the space character # with a newline character. f3.write(str(result)+" ")
我希望这证明是有用的。