[SciPy-user] does vectorize optimize ?

Anne Archibald peridot.faceted at gmail.com
Thu Jan 25 13:31:57 CST 2007


On 25/01/07, Stef Mientki <s.mientki at ru.nl> wrote:
> does vectorize optimize the performance,
> by trying to move the for-loop to the innermost algorithm,
> or is it just meant for easy writing ?

Vectorize uses frompyfunc, which does not disassemble the python
function and attempt to move loops around or use ufuncs. (For that,
you want something like numexpr.) So, in particular, vectorize(lambda
x, y: x+y)(a,b) will not be nearly as fast as a+b because it will call
the python closure many times. However, it is faster than looping in
python because all the allocation and loop indexing is done in C.
Finally, don't underestimate convenience.

Anne M. Archibald


More information about the SciPy-user mailing list