I have a very large file (~20 GB) from which I want to read specific lines which represent a matrix. The data file for three 2 x 2 matrices looks like:
2 3
1 3
2 2
1 2
3 2
3 4
Currently I am using the following approach (from here) where I get a list of strings.
import itertools
import matplotlib.pyplot as plt
n = 2 # matrix size
t = 3 # number of matrices
file = open("data")
t = 0;
with file as f:
while t < 3:
t=t+1
next_n_lines = list(islice(f, n))
print(next_n_lines)
plt.matshow(next_n_lines)
plt.show()
if not next_n_lines:
break
# process next_n_lines
But how do I get floats instead of a list of strings? I don't see it, but it can't be so hard.