my loop is too slow

Tim Hochberg hochberg at psn.net
Tue May 11 16:24:39 EDT 1999


Joe Strout wrote in message ...

[SNIP]
>2. If you're doing something that can be expressed in linear algebra,
>consider using the Numeric module; it is MUCH faster than standard
>Python at such operations.
[SNAP]

FWIW: Taking into account Michael Haggerty's observation on that this is
really a matrixmultiply of (c.f)(c.transpose(f)), I reimplemented the
original loop as:

from Numeric import *
a = a + dot(c, f) * dot(c, transpose(f))

This improved the speed a lot. In fact the above runs in less than a second
on a P300 machine with len(a)=142.

-tim






More information about the Python-list mailing list