Challenge - 5 Problems
Convolution Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of 1D convolution with zero padding
What is the output array after performing a 1D convolution of signal [1, 2, 3] with kernel [0, 1, 0.5] using zero padding?
Signal Processing
import numpy as np signal = np.array([1, 2, 3]) kernel = np.array([0, 1, 0.5]) output = np.convolve(signal, kernel, mode='same') print(output.tolist())
Attempts:
2 left
💡 Hint
Remember that 'same' mode returns output of the same length as the input signal.
✗ Incorrect
The 'same' mode in numpy.convolve returns the central part of the convolution, matching the input length. The calculation with zero padding (kernel flipped to [0.5, 1, 0]): [0*0 + 1*0.5 + 2*1, 1*0 + 2*0.5 + 3*1, 2*0 + 3*0.5 + 0*1] = [1.0, 2.5, 4.0].
❓ data_output
intermediateLength of convolution output
Given two discrete signals of lengths 7 and 5, what is the length of their full convolution output?
Attempts:
2 left
💡 Hint
The length of full convolution output is sum of lengths minus 1.
✗ Incorrect
For two signals of lengths M and N, full convolution length is M + N - 1. Here, 7 + 5 - 1 = 11.
🔧 Debug
advancedIdentify the error in convolution code
What error will this code raise?
import numpy as np
signal = np.array([1, 2, 3])
kernel = np.array([0.5, 1])
output = np.convolve(signal, kernel, mode='invalid_mode')
print(output)
Signal Processing
import numpy as np signal = np.array([1, 2, 3]) kernel = np.array([0.5, 1]) output = np.convolve(signal, kernel, mode='invalid_mode') print(output)
Attempts:
2 left
💡 Hint
Check the allowed mode strings for numpy.convolve.
✗ Incorrect
numpy.convolve only accepts 'full', 'valid', or 'same' as mode. Using 'invalid_mode' raises a ValueError.
🧠 Conceptual
advancedEffect of kernel flipping in convolution
Which statement correctly describes the role of kernel flipping in the convolution operation?
Attempts:
2 left
💡 Hint
Think about how convolution differs from correlation.
✗ Incorrect
Convolution involves flipping the kernel before sliding it over the signal, unlike correlation which does not flip the kernel.
🚀 Application
expertVisualizing 2D convolution output shape
You have a 2D image of size 28x28 pixels and a 2D kernel of size 5x5. Using 'valid' convolution mode (no padding), what will be the shape of the output image after convolution?
Attempts:
2 left
💡 Hint
Output size in 'valid' mode is input size minus kernel size plus 1.
✗ Incorrect
For 'valid' mode, output height = 28 - 5 + 1 = 24, and output width = 28 - 5 + 1 = 24.
