Slow Python - what can be done?

Michael Ressler ressler at cheetah.jpl.nasa.gov
Thu Mar 18 13:06:46 EST 2004


In article <480e9240.0403180943.64bee13d at posting.google.com>, Jason wrote:
> Basically, you specify two directed line segments in the coordinate
> system of a raster image and use the difference between those two
> lines to transform the image.

>     # This is the slow part of the program
>         dest = list(self.data.getdata())
>         src = source.data.getdata()
>         for x in range(0, self.data.size[0] - 1):
>             for y in range(0, self.data.size[1] - 1):

"For loops" are evil ;-)  Though I'm not familiar with your algorithm, you
should investigate the Numeric/numarray package, which is designed to
do lots of number crunching fast. If you can cast your problem into
good Numeric form, you'll see a speedup of a factor of hundreds.

Mike

-- 
Dr. Michael Ressler
Research Scientist, Astrophysics Research Element, Jet Propulsion Laboratory
Email: ressler at cheetah.jpl.nasa.gov      Phone: (818)354-5576
"A bad night at the telescope is still better than the best day at the office."



More information about the Python-list mailing list