Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay, so you can do this:</p> <p>Algorithm:</p> <pre><code>Read the file line by line if the line starts with "timestep": read the next three lines take the average as needed </code></pre> <p>Code:</p> <pre><code>def getArrays(f): answer = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] count = 0 line = f.readline() while line: if line.strip().startswith("timestep"): one, two, three = getFloats(f.readline().strip()), getFloats(f.readline().strip()), getFloats(f.readline().strip()) answer[0][0] = ((answer[0][0]*count) + one[0])/(count+1) answer[0][1] = ((answer[0][0]*count) + one[1])/(count+1) answer[0][2] = ((answer[0][0]*count) + one[2])/(count+1) answer[1][0] = ((answer[0][0]*count) + two[0])/(count+1) answer[1][1] = ((answer[0][0]*count) + two[1])/(count+1) answer[1][2] = ((answer[0][0]*count) + two[2])/(count+1) answer[2][0] = ((answer[0][0]*count) + three[0])/(count+1) answer[2][1] = ((answer[0][0]*count) + three[1])/(count+1) answer[2][2] = ((answer[0][0]*count) + three[2])/(count+1) line = f.readline() count += 1 return answer def getFloats(line): answer = [] for num in line.split(): if "E" in num: parts = num.split("E") base = float(parts[0]) exp = int(parts[1]) answer.append(base**exp) else: answer.append(float(num)) return answer </code></pre> <p><code>answer</code> is now a list of all the 3x3 arrays. I don't know how you want to do the averaging, so if you post that, I can incorporate it into this algorithm. Else, you can write a function to take my array and compute the averages are required.</p> <p>Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload