[Numpy-discussion] Assignment from a list is slow in Numarray

Francesc Alted falted at pytables.org
Sun Sep 19 23:54:02 CDT 2004


A Diumenge 19 Setembre 2004 19:35, Timo Korvola va escriure:
> My code for reading a triangulation from a file went roughly
> like this:
> 
> coord = zeros( (n_vertices, 2), Float)
> for v in n_vertices:
>     coord[ v, :] = [float( s) for s in file.readline().split()]
> 
> This was taking quite a bit of time with ~50000 vertices and ~100000
> elements, for which three integers per element are read in a similar
> manner.  I found it was faster to loop explicitly:
> 
> coord = zeros( (n_vertices, 2), Float)
> for v in n_vertices:
>     for j, c in enumerate( [float( s) for s in file.readline().split()]):
>         coord[ v, j] = c
> 
> Morally this uglier code with an explicit loop should not be faster
> but it is with Numarray.  With Numeric assignment from a list has
> reasonable performance.  How can it be improved for Numarray?

If you want to achieve fast I/O with both numarray/Numeric, you may want to
try PyTables (wwww.pytables.org). It supports numarray objects natively, so
you should get pretty fast performance. At the beginning, you will need to
export your data to a PyTables file, but then you can read data as many
times as you want from it.

HTH

-- 
Francesc Alted





More information about the Numpy-discussion mailing list