Reputation: 467
I am having trouble to read a matrix from a text file to a numpy array very fast without any unnecessary copying.
The format is the following:
3
1 -1 6 5 9 7 0 -7
0 -5 -5 3 -7 -2 4 3
-2 -9 -5 6 6 -2 -9 9
-7 -3 3 -3 3 8 8 -8
9 3 5 2 -2 4 6 5
-1 -8 7 -4 -1 3 7 4
0 -4 -8 -3 2 6 2 -2
-1 8 6 5 9 8 0 6
The first line (3) indicates the size of the matrix i.e here it is 2^3 = 8x8 matrix
Each column is separated with a \t
character and each line is separated with a \n
character.
I have tried numpy.loadtxt()
, I can specify the row delimiter, skip the first row (the 3) but then I need to specify a column delimiter. Can anyone help please?
Upvotes: 0
Views: 542
Reputation: 467
@juanpa the loadtxt(path, skiprows=1) works perfectly, thank you so much!
Upvotes: 1