<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/numpy.py#L1573-L1617) |

Count the number of occurrences of each value in a tensor of integers.

#### View aliases


**Main aliases**

[`tf.keras.ops.numpy.bincount`](https://www.tensorflow.org/api_docs/python/tf/keras/ops/bincount)

<br />

    tf.keras.ops.bincount(
        x, weights=None, minlength=0, sparse=False
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `x` | Input tensor. It must be of dimension 1, and it must only contain non-negative integer(s). |
| `weights` | Weight tensor. It must have the same length as `x`. The default value is `None`. If specified, `x` is weighted by it, i.e. if `n = x[i]`, `out[n] += weight[i]` instead of the default behavior `out[n] += 1`. |
| `minlength` | An integer. The default value is 0. If specified, there will be at least this number of bins in the output tensor. If greater than `max(x) + 1`, each value of the output at an index higher than `max(x)` is set to 0. |
| `sparse` | Whether to return a sparse tensor; for backends that support sparse tensors. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| 1D tensor where each element gives the number of occurrence(s) of its index value in x. Its length is the maximum between `max(x) + 1` and minlength. ||

<br />

#### Examples:

    x = keras.ops.array([1, 2, 2, 3], dtype="uint8")
    keras.ops.bincount(x)
    array([0, 1, 2, 1], dtype=int32)
    weights = x / 2
    weights
    array([0.5, 1., 1., 1.5], dtype=float64)
    keras.ops.bincount(x, weights=weights)
    array([0., 0.5, 2., 1.5], dtype=float64)
    minlength = (keras.ops.max(x).numpy() + 1) + 2 # 6
    keras.ops.bincount(x, minlength=minlength)
    array([0, 1, 2, 1, 0, 0], dtype=int32)