Complete the code to apply a median filter to the array.
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)
The median_filter function requires the size parameter to specify the window size. A size of 3 means the median is computed over 3 elements.
Complete the code to apply a uniform filter with a window size of 4.
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)
The uniform_filter smooths the array by averaging over a window of the given size. Here, size=4 means averaging over 4 elements.
Fix the error in the code to correctly apply a median filter with size 3.
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)
The correct parameter name for the window size in median_filter is size. Using other names causes an error.
Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.
words = ['data', 'is', 'fun', 'and', 'easy'] lengths = {word: [1] for word in words if [2] print(lengths)
The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3 using len(word) > 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 2.
words = ['Hi', 'Data', 'AI', 'Science'] result = { [1]: [2] for word in words if [3] } print(result)
The dictionary comprehension maps the uppercase version of each word (word.upper()) to its length (len(word)) only if the length is greater than 2 (len(word) > 2).