Q:

Write a Python program to count number of occurrences of each value in a given array of non-negative integers

0

Write a Python program to count number of occurrences of each value in a given array of non-negative integers.

Note: bincount() function count number of occurrences of each value in an array of non-negative integers in the range of the array between the minimum and maximum values including the values that did not occur.

All Answers

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

import numpy as np
array1 = [0, 1, 6, 1, 4, 1, 2, 2, 7] 
print("Original array:")
print(array1)
print("Number of occurrences of each value in array: ")
print(np.bincount(array1))

Sample Output:

Original array:
[0, 1, 6, 1, 4, 1, 2, 2, 7]
Number of occurrences of each value in array: 
[1 3 2 0 1 0 1 1]

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