jax.numpy.bincount(x, weights=None, minlength=0, *, length=None)[source]#

Count number of occurrences of each value in array of non-negative ints.

LAX-backend implementation of numpy.bincount().

Jax adds the optional length parameter which specifies the output length, and defaults to x.max() + 1. It must be specified for bincount to be compiled with non-static operands. Values larger than the specified length will be discarded. If length is specified, minlength will be ignored.

Additionally, while np.bincount raises an error if the input array contains negative values, jax.numpy.bincount clips negative values to zero.

Original docstring below.

The number of bins (of size 1) is one larger than the largest value in x. If minlength is specified, there will be at least this number of bins in the output array (though it will be longer if necessary, depending on the contents of x). Each bin gives the number of occurrences of its index value in x. If weights is specified the input array is weighted by it, i.e. if a value n is found at position i, out[n] += weight[i] instead of out[n] += 1.

  • x (array_like, 1 dimension, nonnegative ints) – Input array.

  • weights (array_like, optional) – Weights, array of the same shape as x.

  • minlength (int, optional) – A minimum number of bins for the output array.

  • length (int | None) –


out – The result of binning the input array. The length of out is equal to np.amax(x)+1.

Return type:

ndarray of ints