[Numpy-discussion] convolving (or correlating) with sliding windows

Davide Cittaro davide.cittaro@ifom-ieo-campus...
Tue Feb 15 10:42:45 CST 2011

Hi all, 
I have to work with huge numpy.array (i.e. up to 250 M long) and I have to perform either np.correlate or np.convolve between those.
The process can only work on big memory machines but it takes ages. I'm writing to get some hint on how to speed up things (at cost of precision, maybe...), possibly using a moving window... is it correct to perform this:

- given a window W and a step size S
- given data1 and data2
- pad with zeros data1 and data2 by adding W/2 0-arrays
- get the np.correlation like

y = np.array([np.correlate(data1[x:x+W], data2[x:x+W], mode='valid') for x in  np.arange(0, len(data1) - W, S)]).ravel()

instead of np.correlate(data1, data2, mode='same')

- interpolate the correlation using scipy.interpolate 


More information about the NumPy-Discussion mailing list