Complete the code to select elements greater than 5 from the array.
import numpy as np arr = np.array([1, 6, 3, 8, 4]) result = arr[arr [1] 5] print(result)
Using arr > 5 creates a boolean mask selecting elements greater than 5.
Complete the code to select elements that are even numbers from the array.
import numpy as np arr = np.array([2, 7, 4, 9, 6]) even_elements = arr[arr [1] 2 == 0] print(even_elements)
The modulo operator % checks the remainder. Even numbers have remainder 0 when divided by 2.
Fix the error in the code to select elements less than 10.
import numpy as np arr = np.array([12, 5, 8, 15, 3]) selected = arr[arr [1] 10] print(selected)
The correct operator to select elements less than 10 is <.
Fill both blanks to create a dictionary of words and their lengths for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if [2] > 3} print(lengths)
Use len(word) to get the length and filter words with length greater than 3.
Fill in the blank to create a dictionary of uppercase words and their lengths for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] result = [1] print(result)
The dictionary comprehension uses word.upper() as keys, len(word) as values, and filters words with length greater than 3.