Q:

Write a NumPy program to count the occurrence of a specified item in a given NumPy array

0

Write a NumPy program to count the occurrence of a specified item in a given NumPy array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now