Write a NumPy program to count the occurrence of a specified item in a given NumPy array.
import numpy as np nums = np.array([10, 20, 20, 20, 20, 0, 20, 30, 30, 30, 0, 0, 20, 20, 0]) print("Original array:") print(nums) print(np.count_nonzero(nums == 10)) print(np.count_nonzero(nums == 20)) print(np.count_nonzero(nums == 30)) print(np.count_nonzero(nums == 0))
Sample Output:
Original array: [10 20 20 20 20 0 20 30 30 30 0 0 20 20 0] 1 7 3 4
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer