我想从附加的文件中提取初始残差值: http://www.filedropper.com/fixvel 但是初始残差必须参考“DICPCG”线而不是其他线(如“smoothsolver”)。然后我想将这些值存储到一个矩阵中,该矩阵包含每个时间步的同一时间步(在同一行上)的初始残差值。
提前非常感谢
答案 0 :(得分:-1)
请尝试以下代码:
import re
import sys
file = open("fixVel.txt")
textfile = file.readlines()
count = -1
matrix = []
for row in textfile:
if row.find("Time") == 0:
count = count + 1
matrix.append([])
if row.find("DICPCG") == 0:
index = row.find("Initial residual")
index1 = row[index:].find(",")
matrix[count].append(row[index+19:index+index1])
#print matrix
for i in matrix:
for j in i:
sys.stdout.write(j + " ")
print