Complete the code to create a mask selecting values greater than 5.
import numpy as np arr = np.array([2, 7, 4, 10, 3]) mask = arr [1] 5
The operator > selects values greater than 5.
Complete the code to select values greater than 3 and less than 8 using logical AND.
import numpy as np arr = np.array([2, 7, 4, 10, 3]) mask = (arr > 3) [1] (arr < 8)
The operator & is used for element-wise logical AND in NumPy arrays.
Fix the error in combining conditions with parentheses.
import numpy as np arr = np.array([1, 5, 8, 3, 7]) mask = (arr > 3) [1] (arr < 8)
Use & with parentheses for element-wise logical AND in NumPy arrays. Python keywords 'and'/'or' do not work element-wise.
Fill both blanks to create a mask selecting values less than 4 or greater than 7.
import numpy as np arr = np.array([2, 5, 3, 9, 7]) mask = (arr [1] 4) [2] (arr > 7)
Use < to select values less than 4 and | for logical OR to combine conditions.
Fill all three blanks to create a dictionary of words and their lengths for words longer than 3 letters and containing 'a'.
words = ['apple', 'bat', 'cat', 'dog', 'ant'] result = { [1]: [2] for word in words if len(word) [3] 3 and 'a' in word }
The dictionary keys are the words themselves (word), values are their lengths (len(word)), and the condition checks if length is greater than 3 (>).