logo       

Re: Assignment from a list is slow in Numarray: msg#00060

python.numeric.general

Subject: Re: Assignment from a list is slow in Numarray

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



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise