bincount#
- ivy.bincount(x, /, *, weights=None, minlength=0, out=None)[source]#
Count the number of occurrences of each value in an integer array.
- Parameters:
self – Input array.
weights (
Optional[Array], default:None) – An optional input array.minlength (
int, default:0) – A minimum number of bins for the output array.
- Return type:
- Returns:
ret – The bincount of the array elements.
Examples
>>> a = ivy.Container([[10.0, ivy.nan, 4], [3, 2, 1]]) >>> a.bincount(a) 3.0 >>> a.bincount(a, axis=0) array([6.5, 2. , 2.5])
- Array.bincount(self, /, *, weights=None, minlength=0, out=None)[source]#
ivy.Array instance method variant of ivy.bincount. This method simply wraps the function, and so the docstring for ivy.bincount also applies to this method with minimal changes.
- Parameters:
self – Input array. The array is flattened if it is not already 1-dimensional.
weights (
Optional[Array], default:None) – Optional weights, array of the same shape as self.minlength (
int, default:0) – A minimum number of bins for the output array.out (
Optional[Array], default:None) – An array of the same shape as the returned array, or of the shape (minlength,) if minlength is specified.
- Return type:
Array- Returns:
ret – The result of binning the input array.
Examples
>>> a = ivy.array([0, 1, 1, 3, 2, 1, 7]) >>> a.bincount() ivy.array([1, 3, 1, 1, 0, 0, 0, 1]) >>> a.bincount(minlength=10) ivy.array([1, 3, 1, 1, 0, 0, 0, 1, 0, 0]) >>> a.bincount(weights=ivy.array([0.3, 0.5, 0.2, 0.7, 1., 0.6, 1.])) ivy.array([0.3, 1.3, 1. , 0.7, 0. , 0. , 0. , 1. ])
- Container.bincount(self, /, *, weights=None, minlength=0, out=None)[source]#
ivy.Array instance method variant of ivy.bincount. This method simply wraps the function, and so the docstring for ivy.bincount also applies to this method with minimal changes.
- Parameters:
self (
Container) – Input array.weights (
Optional[Container], default:None) – An optional input array.minlength (
Union[int,Container], default:0) – A minimum number of bins for the output array.
- Return type:
Container- Returns:
ret – The bincount of the array elements.
Examples
>>> a = ivy.Container([[10.0, ivy.nan, 4], [3, 2, 1]]) >>> a.bincount(a) 3.0 >>> a.bincount(a, axis=0) array([6.5, 2. , 2.5])