[Numpy-discussion] greedy loadtxt

Christopher Barker Chris.Barker@noaa....
Thu Mar 27 14:25:06 CDT 2008

lorenzo bolla wrote:
> The problem with fromfile() is that it doesn't know anything about ndarrays.
> If my file is a table of ncols and nrows, fromfile() will give me a 
> 1darray with nrows*ncols elements, while loadtxt() will give me a 
> 2dmatrix nrows x ncols. In other words, I loose the "shape" of the table.

yup -- you need to know something about the shape. It also doesn't 
support comments, and all sorts of other stuff. It is, however, very 
fast. I mostly use it to read more complex file formats, ones that first 
tell you haw many numbers there are, then have the numbers. It works 
great for that.

hmm-- I wonder how hard it would be to special case linefeeds (from 
other white space) in fromfile(), and have it figure out the shape from 


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the Numpy-discussion mailing list