mindspore.ops.Bincount
- class mindspore.ops.Bincount[source]
Counts the number of occurrences of each value in an integer array.
- Inputs:
array (Tensor) - A Tensor of type int32.
size (Tensor) - A non-negative Tensor of type int32.
weights (Tensor) - A Tensor with the same shape as array, or a length-0 Tensor, in which case it acts as all weights equal to 1. Must be one of the following types: int32, int64, float32, float64.
- Outputs:
A Tensor. Has the same type as weights.
- Raises
TypeError – If dtype of array is not int32.
TypeError – If dtype of size is not int32.
ValueError – If size is negative.
ValueError – If weights are empty.
ValueError – If size of weights is not zero and the shape of weights is different with the shape of array.
TypeError – If dtype of weights is not in int32,int64,float32,float64
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> array = Tensor(np.array([1, 2, 2, 3, 3, 3, 4, 4, 4, 4]), mindspore.int32) >>> size = Tensor(5, mindspore.int32) >>> weights = Tensor(np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), mindspore.float32) >>> bincount = ops.Bincount() >>> bins = bincount(array, size, weights) >>> print(bins) [0. 1. 2. 3. 4.]