oneflow.bincount¶
-
oneflow.bincount()¶ oneflow.bincount(input, weights=None, minlength=0) → Tensor
The interface is consistent with PyTorch.
The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.bincount.html.
Count the frequency of each value in an array of non-negative ints.
The number of bins (size 1) is one larger than the largest value in
inputunlessinputis empty, in which case the result is a tensor of size 0. Ifminlengthis specified, the number of bins is at leastminlengthand ifinputis empty, then the result is tensor of sizeminlengthfilled with zeros. Ifnis the value at positioni,out[n] += weights[i]ifweightsis specified elseout[n] += 1.- Parameters
input (oneflow.Tensor) – 1-d int Tensor
weights (oneflow.Tensor) – optional, weight for each value in the input tensor. Should be of same size as input tensor.
minlength (int) – optional, minimum number of bins. Should be non-negative.
For example:
>>> import oneflow as flow >>> x = flow.tensor([1, 2, 4, 6]) >>> flow.bincount(x) tensor([0, 1, 1, 0, 1, 0, 1], dtype=oneflow.int64) >>> x = flow.tensor([1, 2, 1]) >>> weights = flow.tensor([0.1, 0.2, 0.15]) >>> flow.bincount(x, weights=weights) tensor([0.0000, 0.2500, 0.2000], dtype=oneflow.float32) >>> flow.bincount(x, weights=weights, minlength=4) tensor([0.0000, 0.2500, 0.2000, 0.0000], dtype=oneflow.float32)