Numeric: fromfunction() performance

jsaul jsaul at
Sat Oct 19 10:48:10 CEST 2002

* Travis Oliphant [2002-10-16 02:07]:
> > What I actually want is a (quicker) construct corresponding to
> >
> >     for i in range(0, nf):
> >         q[i] = cmath.exp(-x1*i*i -1j*i*x2)
> >
> i = Numeric.arange(0,nf)
> q = Numeric.exp(-x1*i*i-1j*i*x2)

Indeed! Thanks a lot, the increase in speed is very significant.
Implementing it as

i = Numeric.arange(1.*nf)
q = Numeric.exp((-x1*i-1j*x2)*i)

yields yet another ~25% performance increase by avoiding the
implicit conversion from Int to Double and one summation through
the brackets. Int32 overflow for large nf (nf>= 2**16) is also

Thanks also to Pearu. Actually the computation forms part of a
frequency filter; the first term in the exp() corresponds to a
Gaussian, while the second results in a time shift.

Gruß, jsaul
Que le gusta rrrodarrr la errre.

More information about the Python-list mailing list