Project DelphiTensors Workshop

Take-home F — convolution and its three modes

Convolution slides a small array — the kernel, or filter — across a larger one, multiplying and summing at each position. It is the operation at the heart of every convolutional neural network, and it is also how every blur, sharpen and edge-detection filter works.

x = np.array([1., 2., 3., 4., 5.]) k = np.array([1., 0., -1.]) np.convolve(x, k, 'full') # length 5+3-1 = 7 np.convolve(x, k, 'valid') # length 5-3+1 = 3 np.convolve(x, k, 'same') # length 5

valid uses only positions where the kernel fits completely — this is why convolution shrinks an image by kernel_size - 1.