Complete the code to count non-zero elements in the array.
import numpy as np arr = np.array([0, 1, 2, 0, 3]) count = np.[1](arr) print(count)
The function np.count_nonzero() counts the number of non-zero elements in the array.
Complete the code to count non-zero elements along axis 0.
import numpy as np arr = np.array([[0, 1, 2], [3, 0, 0]]) count = np.count_nonzero(arr, axis=[1]) print(count)
Setting axis=0 counts non-zero elements down each column.
Fix the error in the code to correctly count non-zero elements in a boolean array.
import numpy as np arr = np.array([True, False, True, False]) count = np.count_nonzero([1]) print(count)
np.count_nonzero() expects the array itself as input, not a sum or indices.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
words = ['cat', 'house', 'dog', 'elephant'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension uses len(word) for values and filters words with length greater than 3.
Fill all three blanks to create a dictionary of uppercase words and their counts if count is greater than 1.
data = {'apple': 2, 'banana': 1, 'cherry': 3}
result = { [1]: [2] for word in data if data[word] [3] 1 }
print(result)The dictionary comprehension creates keys as uppercase words, values as counts, filtering counts greater than 1.