What is its purpose? I tried reading the official site but wasn’t able to understand.
Advertisement
Answer
bincount
returns the count of values in each bin from 0 to the largest value in the array i.e.
JavaScript
x
3
1
np.bincount(my_list) == [count(i) for i in range(0, max(my_list))]
2
== [count(0), count(1), , count(max(my_list))]
3
e.g.
JavaScript
1
3
1
np.bincount([0, 1, 2, 3, 4, 4, 6])
2
>>> array([1, 1, 1, 1, 2, 0, 1])
3
Note:
- absent numbers (e.g.
5
above) return a count of0
- a
ValueError
is raised if the list contains negative numbers orNaN