0

I have been trying to translate a matlab code for convn(...) recently and stopped at scipy after I found out about scipy.signal.fftconvolve As Matlabs convn allows a NxNxD (with D = 100 in my case). It seems that fftconvolve will not perform the same operation for the following code

#kernel is a 5x5 kernel, first expand the kernel to D=100 to match the depth of input array
kernelND = np.repeat(kernel[:,:,np.newaxis], 100, axis=2)

# 'input' is  28x28x100
result = fftconvolve(input, kernelND, mode='valid') 

What I get in result is a 24x24x1 value. This is incorrect as I thought of a result 24x24x100 just like matlab.

Any tips towards the error highly appreciate!

Wajih
  • 793
  • 3
  • 14
  • 31
  • Based on the linked dup question, just directly feed that extended version of kernel into the call : `fftconvolve(input_arr, kernel[:,:,np.newaxis], mode='valid')`. – Divakar Sep 03 '16 at 14:29
  • Thanks for pointing out the duplicity :) I got it right now! – Wajih Sep 03 '16 at 14:48

0 Answers0