tf.keras.ops.bincount
Stay organized with collections
Save and categorize content based on your preferences.
Count the number of occurrences of each value in a tensor of integers.
tf.keras.ops.bincount(
x, weights=None, minlength=0, sparse=False
)
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.
|
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.
|
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)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-07 UTC."],[],[]]