Reading non-uniform data from file into array with NumPy
You can also use numpy.fromstring()
for line in f: a = numpy.fromstring(line.strip(), dtype=int, sep=" ")
or -- if you want full flexibility -- even numpy.loadtxt()
:
for line in f: a = numpy.loadtxt(StringIO.StringIO(line), dtype=int)
For long lines, these solution will perform better than the Python code in the other answers.