mindspore.ops.log2

mindspore.ops.log2(x)[source]

Returns a new tensor with the logarithm to the base 2 of the elements of input.

\[y_i = log_2(x_i)\]

Warning

If the input value of operator Log2 is within the range (0, 0.01] or [0.95, 1.05], the output accuracy may be affacted. If the input value of operator Log2 is less than or equal to 0, it will not raise Error.

Note

The dimension of the input Tensor on Ascend should be less than or equal to 8, and the dimension of the input Tensor on the CPU or GPU should be less than 8.

Parameters

x (Tensor) – Input Tensor of any dimension. The value must be greater than 0.

Returns

Tensor, has the same shape and dtype as the x.

Raises
  • TypeError – If x is not a Tensor.

  • TypeError – If dtype of x is not float16 or float32 or float64 on CPU and GPU, if dtype of x is not float16 or float32 on Ascend.

Supported Platforms:

Ascend GPU CPU

Examples

>>> x = Tensor(np.array([2, 4, 8]).astype(np.float16))
>>> output = ops.log2(x)
>>> print(output)
[1. 2. 3.]