mindspore.ops.population_count

View Source On Gitee
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
  • TypeError – If input_x is not a Tensor.

  • TypeError – If dtype of input_x is not int16, uint16 (Ascend).

  • TypeError – If dtype of input_x is not int8, int16, int32, int64, uint8, uint16, uint32, uint64 (CPU and GPU).

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]