Complete the code to create a boolean mask that selects values greater than 5.
import numpy as np arr = np.array([3, 7, 2, 9, 5]) mask = arr [1] 5 print(mask)
The operator > creates a boolean mask selecting values greater than 5.
Complete the code to use the boolean mask to select values greater than 5 from the array.
import numpy as np arr = np.array([3, 7, 2, 9, 5]) mask = arr > 5 selected = arr[1]mask] print(selected)
Using square brackets [] applies the boolean mask to select elements.
Fix the error in the code to correctly create a mask for values less than or equal to 4.
import numpy as np arr = np.array([1, 4, 6, 3, 8]) mask = arr [1] 4 print(mask)
The operator <= selects values less than or equal to 4, matching the requirement.
Complete the code to create a dictionary of words and their lengths, but only for words longer than 3 letters.
words = ['cat', 'elephant', 'dog', 'lion'] lengths = {word: len(word) for word in words if len(word) [1] 3} print(lengths)
Use : to map word to its length, and > to filter words longer than 3 letters.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words with length greater than 3.
words = ['apple', 'bat', 'carrot', 'dog'] result = [1]: [2] for w in words if len(w) [3] 3 print(result)
w.lower() instead of uppercase keys.Use w.upper() for keys, len(w) for values, and filter with > for length greater than 3.