Google News
logo
NumPy - Interview Questions
What is the procedure to count the number of times a given value appears in an array of integers?
You can count the number of the times a given value appears using the bincount() function. It should be noted that the bincount() function accepts positive integers or boolean expressions as its argument. Negative integers cannot be used. 
 
Use NumPy.bincount(). The resulting array is

arr = NumPy.array([0, 5, 4, 0, 4, 4, 3, 0, 0, 5, 2, 1, 1, 9])
 
NumPy.bincount(arr)
Advertisement