bincount#

ivy.bincount(x, /, *, weights=None, minlength=0, out=None)[source]#

Counts the number of occurrences of each value in an integer array.

Parameters:
  • self – Input array.

  • weights (Optional[Array]) – An optional input array. (default: None)

  • minlength (int) – A minimum number of bins for the output array. (default: 0)

Return type:

Array

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)#

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]) – Optional weights, array of the same shape as self. (default: None)

  • minlength (int) – A minimum number of bins for the output array. (default: 0)

  • out (Optional[Array]) – An array of the same shape as the returned array, or of the shape (default: None) (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)#

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]) – An optional input array. (default: None)

  • minlength (int) – A minimum number of bins for the output array. (default: 0)

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])