mindspore.ops.log2

mindspore.ops.log2(input)[source]

Returns a new Tensor by taking the base 2 logarithm of the elements in the input Tensor.

\[y_i = log_2(input_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 affected.

Parameters

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

Returns

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

Raises
  • TypeError – If input is not a Tensor.

  • TypeError – If dtype of input is not float16 or float32 or float64 on CPU and GPU, if dtype of input 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.]