简体   繁体   中英

Read numpy array(matrix) fast from text file

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 ie 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?

@juanpa的loadtxt(path,skiprows = 1)可以完美运行,非常感谢!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM