Reputation:
I want to load a txt file into a numpy array. The file has this format:
1,10,1,11,1,13,1,12,1,1,9
2,11,2,13,2,10,2,12,2,1,9
3,12,3,11,3,13,3,10,3,1,9
4,10,4,11,4,1,4,13,4,12,9
4,1,4,13,4,12,4,11,4,10,9
1,2,1,4,1,5,1,3,1,6,8
1,9,1,12,1,10,1,11,1,13,8
2,1,2,2,2,3,2,4,2,5,8
3,5,3,6,3,9,3,7,3,8,8
4,1,4,4,4,2,4,3,4,5,8
.
.
.
a width of 11 values and a height of 25010 (so I don't want to put them manually into the array)
I already tried load
, loadtxt
, loadfile
and genfromtxt
. All of them failed.
I'm pretty sure the commas are the problem.
You have a solution?
Upvotes: 1
Views: 12811
Reputation: 3133
You need to specify the delimiter as ,
:
import numpy as np
data = np.loadtxt("file.txt", delimiter=",")
Upvotes: 9