0
0
SciPydata~10 mins

Convolution (convolve) in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the convolve function from scipy.signal.

SciPy
from scipy.signal import [1]
Drag options to blanks, or click blank then click option'
Aconvolve2d
Bfftconvolve
Ccorrelate
Dconvolve
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong function like fftconvolve or correlate.
Forgetting to import from scipy.signal.
2fill in blank
medium

Complete the code to perform convolution of arrays a and b using scipy.signal.convolve.

SciPy
result = convolve(a, [1])
Drag options to blanks, or click blank then click option'
Ab
Ba
C[1, 2, 3]
Dc
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same array twice.
Passing a list literal instead of the variable.
3fill in blank
hard

Fix the error in the code to specify the convolution mode as 'full'.

SciPy
result = convolve(a, b, mode=[1])
Drag options to blanks, or click blank then click option'
A'same'
B'valid'
C'full'
D'partial'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid mode like 'partial'.
Forgetting quotes around the mode string.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each element x in data to its convolution with kernel, only if x is greater than 0.

SciPy
{x: convolve([x], kernel, mode=[1]) for x in data if x [2] 0}
Drag options to blanks, or click blank then click option'
A'valid'
B>
C<
D'same'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'valid' mode which reduces output size.
Using '<' instead of '>' in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each key k.upper() to the convolution of its value v with kernel, only if v is positive.

SciPy
{ [1]: convolve([2], kernel, mode='full') for k, v in data.items() if v [3] 0 }
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original key without uppercasing.
Using '<' instead of '>' in the condition.
Passing the key instead of the value to convolve.