Hi all,
I am trying to port some code written in Python. It performs a 1d convolution on a 3d array. The Python and Julia code output arrays with different dimensions and values. Does anyone know the equivalent code on Julia?
Julia
using DSP
x = [0 0 1 2 3 5 0 0; 0 0 4 5 6 5 0 0 ;;; 0 0 2 3 4 5 0 0 ; 0 0 5 6 7 5 0 0]
z = [5,6,7,10]
conv(x, z)
output:
5×8×2 Array{Int64, 3}:
[:, :, 1] =
0 0 5 10 15 25 0 0
0 0 26 37 48 55 0 0
0 0 31 44 57 65 0 0
0 0 38 55 72 85 0 0
0 0 40 50 60 50 0 0
[:, :, 2] =
0 0 10 15 20 25 0 0
0 0 37 48 59 55 0 0
0 0 44 57 70 65 0 0
0 0 55 72 89 85 0 0
0 0 50 60 70 50 0 0
Python
import scipy
x1 = np.array([[0,0,1,2,3,5,0,0],[0,0,4,5,6,5,0,0]])
x2 = np.array([[0,0,2,3,4,5,0,0],[0,0,5,6,7,5,0,0]])
x = np.dstack((x1, x2))
z = [5,6,7,10]
scipy.ndimage.convolve1d(x, z, axis=1, mode='constant', cval=0)
output:
array([[[ 5, 10],
[ 16, 27],
[ 34, 52],
[ 67, 90],
[ 71, 88],
[ 65, 75],
[ 50, 50],
[ 0, 0]],
[[ 20, 25],
[ 49, 60],
[ 88, 106],
[136, 159],
[122, 139],
[ 95, 105],
[ 50, 50],
[ 0, 0]]])