mindspore.ops.population_count
- mindspore.ops.population_count(input_x)[source]
Computes element-wise population count(a.k.a bitsum, bitcount). For each entry in input_x, calculates the number of 1 bits in the binary representation of that entry.
- Parameters
input_x (Tensor) – Tensor of any dimension. The data type must be int16 or uint16 (Ascend). The data type must be int8, int16, int32, int64, uint8, uint16, uint32, uint64 (CPU and GPU).
- Returns
Tensor, with the same shape as the input, and the data type is uint8.
- Raises
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> from mindspore import Tensor, ops >>> input_x = Tensor([0, 1, 3], mindspore.int16) >>> output = ops.population_count(input_x) >>> print(output) [0 1 2]