0
0
SciPydata~10 mins

Median and uniform filters 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 apply a median filter to the array.

SciPy
from scipy.ndimage import median_filter
import numpy as np

arr = np.array([1, 2, 80, 4, 5])
filtered = median_filter(arr, size=[1])
print(filtered)
Drag options to blanks, or click blank then click option'
A3
B5
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using size=0 or size=1 which does not change the array.
Using an even number for size which is less common for median filters.
2fill in blank
medium

Complete the code to apply a uniform filter with a window size of 4.

SciPy
from scipy.ndimage import uniform_filter
import numpy as np

arr = np.array([10, 20, 30, 40, 50])
filtered = uniform_filter(arr, size=[1])
print(filtered)
Drag options to blanks, or click blank then click option'
A3
B2
C5
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using size=3 or size=5 which changes the smoothing window.
Confusing size with the array length.
3fill in blank
hard

Fix the error in the code to correctly apply a median filter with size 3.

SciPy
from scipy.ndimage import median_filter
import numpy as np

arr = np.array([5, 10, 15, 20, 25])
filtered = median_filter(arr, [1])
print(filtered)
Drag options to blanks, or click blank then click option'
Asize=3
Bwindow=3
Clength=3
Dfilter_size=3
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like window or length.
Omitting the parameter name and just passing a number.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.

SciPy
words = ['data', 'is', 'fun', 'and', 'easy']
lengths = {word: [1] for word in words if [2]
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword.startswith('a')
Dword == 'data'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using a condition unrelated to length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 2.

SciPy
words = ['Hi', 'Data', 'AI', 'Science']
result = { [1]: [2] for word in words if [3] }
print(result)
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 2
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase instead of uppercase for keys.
Not filtering words by length correctly.