Complete the code to count how many values in the array are True.
import numpy as np arr = np.array([True, False, True, True, False]) count_true = np.[1](arr)
Using np.sum() on a boolean array counts how many values are True because True is treated as 1 and False as 0.
Complete the code to count how many values in the array are False.
import numpy as np arr = np.array([True, False, True, False, False]) count_false = np.[1](~arr)
Using np.sum() on the negated array ~arr counts how many values are False in the original array.
Fix the error in the code to count True values along axis 0.
import numpy as np arr = np.array([[True, False], [False, True], [True, True]]) count_true_axis0 = np.sum(arr, axis=[1])
Axis 0 means counting down the rows for each column. So axis=0 sums True values column-wise.
Fill both blanks to create a dictionary counting words longer than 3 letters.
words = ['apple', 'bat', 'car', 'door', 'egg'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension stores the length of each word. The condition filters words with length greater than 3.
Fill all three blanks to create a dictionary of uppercase words and their lengths if length > 3.
words = ['apple', 'bat', 'car', 'door', 'egg'] result = { [1]: [2] for [3] in words if len([3]) > 3 }
The dictionary comprehension uses uppercase words as keys and their lengths as values, filtering words longer than 3 letters.