bincount#
- bamengine.ops.bincount(a, minlength=0)[source]#
Count occurrences of each value in array of non-negative ints.
- Parameters:
a (
int array) – Array of non-negative integers.minlength (
int, optional) – Minimum length of output array.
- Returns:
Count of occurrences of each value.
- Return type:
int array
Examples
>>> import bamengine.ops as ops >>> # Count how many workers each firm employs >>> employer_ids = np.array([0, 0, 1, 2, 0, 1]) # 6 workers >>> workers_per_firm = ops.bincount(employer_ids, minlength=5) >>> # workers_per_firm: [3, 2, 1, 0, 0] >>> # Firm 0 has 3 workers, firm 1 has 2, firm 2 has 1