I'm trying to read floats from a text file into a 2d array. The file has the following structure:
1.1
3.3
2.4576
0.2432
1.3
235.234
I wish to read these lines into a 2d list, and end up with the following.
data = [[1.1, 3.3]
[2.4576, 0.2432]
...
[1.3, 235.234]]
My code so far:
f = []
with open(str(i)) as fl:
for line in fl:
f.append(float(line))
Is there an easy and "nice" way to do it, without using a lot of help variables?
(Both the length of the file and the size of the array(x*x) are known)