Search code examples
numpysampleconvolutionsmoothing

numpy resampling reshape data


I convolved a specific 1D size data set and the output was a larger 1D dataset. Is there a way to resample the data to the original size before convolving?

Here is what I used to convolve that data Kp1smo=np.convolve(Kp1,np.ones(5)/5))


Solution

  • If you want the output of the convolution to be the same size as the input Kp1 you could do the convolution using the 'same' option:

    Kp1smo=np.convolve(Kp1,np.ones(5)/5),'same')
    

    According to the documentation for numpy.convolve this will return a result of size max(M,N), where M and N are the size of the two input vectors. If Kp1 is larger than 5 this will be the size of Kp1.

    With no argument, numpy.convolve defaults to 'full' mode which gives a result of size (N+M-1)