Challenge - 5 Problems
Convolution Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of 1D convolution with 'full' mode
What is the output of this code snippet using
scipy.signal.convolve with mode='full'?SciPy
import numpy as np from scipy.signal import convolve x = np.array([1, 2, 3]) h = np.array([0, 1, 0.5]) result = convolve(x, h, mode='full') print(result)
Attempts:
2 left
💡 Hint
Remember that 'full' mode returns the complete convolution, including edges.
✗ Incorrect
The convolution sums products of overlapping elements. With mode='full', the output length is len(x)+len(h)-1 = 5. The calculation yields [0, 1, 2.5, 4, 1.5].
❓ data_output
intermediate1:30remaining
Length of convolution result with 'valid' mode
Given two arrays
a and b of lengths 7 and 3 respectively, what is the length of the result when convolving with mode='valid'?SciPy
from scipy.signal import convolve a = [1,2,3,4,5,6,7] b = [0,1,0.5] result = convolve(a, b, mode='valid') print(len(result))
Attempts:
2 left
💡 Hint
Length in 'valid' mode is len(a) - len(b) + 1.
✗ Incorrect
In 'valid' mode, convolution only includes points where arrays fully overlap, so length is 7 - 3 + 1 = 5.
🔧 Debug
advanced2:00remaining
Identify the error in convolution code
What error will this code raise when run?
SciPy
import numpy as np from scipy.signal import convolve x = np.array([1, 2, 3]) h = np.array([[0, 1], [0.5, 0]]) result = convolve(x, h) print(result)
Attempts:
2 left
💡 Hint
Check the shapes of the input arrays for convolution.
✗ Incorrect
The 1D array x and 2D array h have different dimensions, so convolve raises a ValueError about dimension mismatch.
❓ visualization
advanced2:30remaining
Plotting convolution result of two signals
Which option correctly plots the convolution of two signals
x and h using matplotlib?SciPy
import numpy as np from scipy.signal import convolve import matplotlib.pyplot as plt x = np.array([1, 2, 3, 4]) h = np.array([0, 1, 0.5]) result = convolve(x, h, mode='full') # Plot code here
Attempts:
2 left
💡 Hint
Use a line plot to show the convolution values clearly.
✗ Incorrect
Using plt.plot shows the convolution as a continuous line, which is standard for signal visualization. Other plots are less clear or less common for this data.
🧠 Conceptual
expert3:00remaining
Effect of convolution mode on output size
Which statement correctly describes the relationship between input sizes and output size for
scipy.signal.convolve modes?Attempts:
2 left
💡 Hint
Recall the definitions of convolution modes and their output sizes.
✗ Incorrect
'full' mode returns the complete convolution with length len(x)+len(h)-1. 'valid' mode returns only points where arrays fully overlap, length len(x)-len(h)+1. 'same' mode returns output the same size as the first input.