Get startedGet started for free

One dimensional convolutions

A convolution of an one-dimensional array with a kernel comprises of taking the kernel, sliding it along the array, multiplying it with the items in the array that overlap with the kernel in that location and summing this product.

This exercise is part of the course

Image Modeling with Keras

View Course

Exercise instructions

Multiply each window in the input array with the kernel and sum the multiplied result and allocate the result into the correct entry in the output array (conv).

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

array = np.array([1, 0, 1, 0, 1, 0, 1, 0, 1, 0])
kernel = np.array([1, -1, 0])
conv = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

# Output array
for ii in range(8):
    conv[ii] = (____ * array[____:____+____]).sum()

# Print conv
print(conv)
Edit and Run Code