Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Image Modeling with Keras

Cursus bekijken

Oefeninstructies

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).

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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)
Code bewerken en uitvoeren