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

Nathan Bell wnbell@gmail....
Tue Feb 5 10:45:06 CST 2008

On Feb 5, 2008 9:15 AM, Jose Luis Gomez Dans <josegomez@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@gmail.com

More information about the SciPy-user mailing list