[SciPy-user] Fastest way to read a matrix in

Nathan Bell wnbell at gmail.com
Tue Feb 5 11:45:06 EST 2008


On Feb 5, 2008 9:15 AM, Jose Luis Gomez Dans <josegomez at gmx.net> wrote:
> Hi!
> I have a large set of matrices on ASCII files stored on disk. Each is made up of a number of M of rows, with N elements on each row separated by spaces. I know beforehand what M and N are, and I want to read them into an MxN array (or is it NxM? :D) I am using scipy.io.read_array(), but the performance is fairly slow (these are 80x80ish arrays). While they are on NFS mounts, other programs read the data in faster than python's scipy.io.read_array, so I was wondering whether there's a faster way of reading the data in (maybe giving hints on the number of columns and rows, using some other function, etc)?

Try numpy.fromfile()

A = fromfile("myfile.txt", dtype=float, count=80*80, sep=' ').reshape(80,80)

-- 
Nathan Bell wnbell at gmail.com
http://graphics.cs.uiuc.edu/~wnbell/



More information about the SciPy-User mailing list