A coworker left some data files I want to analyze with Numpy.
Each file is a matlab file, say data.m
, and have the following formatting (but with a lot more
You could feed an iterator to np.genfromtxt
:
import numpy as np
import re
with open(filename, 'r') as f:
lines = (re.sub(r'[^-+.0-9 ]+', '', line) for line in f)
arr = np.genfromtxt(lines)
print(arr)
yields
[[-24.92 -23.66 -22.55]
[-24.77 -23.56 -22.45]
[-24.54 -23.64 -22.56]]
Thanks to Bitwise for clueing me in to this answer.