Hi John,
I saw that you add in the load function the possibility to have some line comment with the character '%'. I would like to change this function and generalize a little bit this. Not everyone is using the character '%' but some other like '#' or '!'. So I add this possibilty to the function. I don't know if you are agree with it but in case I join the change below.
Another things, I think there are a small bug for the Tkagg backend. When I close the windows instead to come back to my shell I'm arriving in a python shell. I tried (when I had my laptop) with the Gtkagg backend and I didn't notice this problem.
Thanks.
Nicolas
def load(fname,comments='%'):
"""
Load ASCII data from fname into an array and return the array.
The data must be regular, same number of values in every row
fname can be a filename or a file handle
matfile data is not currently supported, but see
Nigel Wade's matfile ftp://ion.le.ac.uk/matfile/matfile.tar.gz
Example usage:
x,y = load('test.dat') # data in two columns
X = load('test.dat') # a matrix of data
x = load('test.dat') # a single column of data
"""
if is_string_like(fname):
fh = file(fname)
elif hasattr(fname, 'seek'):
fh = fname
else:
raise ValueError('fname must be a string or file handle')
X = []
numCols = None
for line in fh:
line = line[:line.find(comments)].strip()
if not len(line): continue
row = [float(val) for val in line.split()]
thisLen = len(row)
if numCols is not None and thisLen != numCols:
raise ValueError('All rows must have the same number of columns')
X.append(row)
X = array(X)
r,c = X.shape
if r==1 or c==1:
X.shape = max([r,c]),
return X