Complete the code to compute the FFT of the signal array.
import numpy as np from scipy.fft import fft signal = np.array([1, 2, 3, 4, 5]) fft_result = [1](signal)
The fft function computes the Fast Fourier Transform of the input signal.
Complete the code to create a frequency mask that keeps frequencies below 10 Hz.
import numpy as np sampling_rate = 50 # Hz n = 100 freqs = np.fft.fftfreq(n, d=1/sampling_rate) mask = np.abs(freqs) [1] 10
The mask should select frequencies less than 10 Hz, so the operator is <.
Fix the error in the code to apply a low-pass filter using FFT.
import numpy as np from scipy.fft import fft, ifft signal = np.sin(2 * np.pi * 5 * np.linspace(0, 1, 100)) + np.sin(2 * np.pi * 20 * np.linspace(0, 1, 100)) fft_signal = fft(signal) freqs = np.fft.fftfreq(len(signal), d=1/100) mask = np.abs(freqs) [1] 10 filtered_fft = fft_signal * mask filtered_signal = ifft(filtered_fft).real
The mask should be True for frequencies less than 10 Hz to keep them, so use <.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
words = ['data', 'science', 'is', 'fun'] lengths = {word: [1] for word in words if len(word) [2] 3}
We want the length of each word, so use len(word). We only want words longer than 3 characters, so use >.
Fill all three blanks to create a filtered dictionary of uppercase keys and values greater than 0.
data = {'a': 1, 'b': -2, 'c': 3}
result = [1]: [2] for k, v in data.items() if v [3] 0The keys are converted to uppercase with k.upper(), values are v, and we filter values greater than 0 with >.