[MATRIX-SIG] Question about Numeric.convolve

Konrad Hinsen hinsen@ibs.ibs.fr
Wed, 11 Feb 1998 19:42:16 +0100


> I'm (trying) to use convolve to convolute a calculation with
> Gaussian resolution and am having some trouble sorting things
> out.  I have two arrays, x and f = f(x) and I'd like to convolute
> f(x) with a Gaussian.  So I calculate an array g like this:
>     g = Numeric.zeros( x.shape,'Float').real
>     for i in range(len(g)):
>  	g[i] = math.exp(-(math.pow((x[i]-mu)/sigma,2)))

First of all, that's complicated and inefficient. NumPy can
do much better:

   g = Numeric.exp(((x-mu)/sigma)**2)

> So, the question is - is there a way to convolute two arrays with
> x, rather than the array index, as the index.  Or am I just
> totally clueless?  Or both?

Numeric.convolve is not what you are looking for, as indeed it
convolutes according to the array index (which is equivalent for
equally-spaced data and much more efficient). A convolution for
unevenly spaced data amounts to a explicit numerical integration. If
that's what you want, well, Simpson's rule is easy enough to implement
in Python.

Konrad.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-4.76.88.99.28
Institut de Biologie Structurale       | Fax:  +33-4.76.88.54.94
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais
-------------------------------------------------------------------------------

_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________