- paddle. bincount ( x, weights=None, minlength=0, name=None ) [source]
Computes frequency of each value in the input tensor.
x (Tensor) – A Tensor with non-negative integer. Should be 1-D tensor.
weights (Tensor, optional) – Weight for each value in the input tensor. Should have the same shape as input. Default is None.
minlength (int, optional) – Minimum number of bins. Should be non-negative integer. Default is 0.
name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.
The tensor of frequency.
- Return type
import paddle x = paddle.to_tensor([1, 2, 1, 4, 5]) result1 = paddle.bincount(x) print(result1) # [0, 2, 1, 0, 1, 1] w = paddle.to_tensor([2.1, 0.4, 0.1, 0.5, 0.5]) result2 = paddle.bincount(x, weights=w) print(result2) # [0., 2.19999981, 0.40000001, 0., 0.50000000, 0.50000000]