for i in range(len(y.shape), len(x.shape)):
    dim = (1,) + dim
y = y.reshape(dim)
origin = ()
for i in range(len(x.shape)):
    if (x.shape[i] - y.shape[i]) % 2 == 0 and x.shape[i] > 1 and y.shape[i
        ] > 1:
        origin = origin + (-1,)
else:
    origin = origin + (0,)
z = convolve(x, y, mode='constant', origin=origin)
return z
Is there a Python equivalent of MATLAB's conv2 function?