mindspore.Tensor.log2
- mindspore.Tensor.log2()
逐元素返回Tensor以2为底的对数。
\[y_i = \log_2(x_i)\]警告
这是一个实验性API,可能会更改或删除。
如果log2的输入值范围在(0, 0.01]或[0.95, 1.05]区间,输出精度可能会受影响。
说明
输入的值必须大于0。
- 返回:
Tensor。具有与 self 相同的shape,并且类型根据 self.dtype 而变化。
如果 self.dtype 的类型是float16、float32、float64、complex64、complex128,那么输出的类型则和 self.dtype 相同。
如果 self.dtype 的类型是double,那么输出的类型为float64。
在Ascend平台中,如果 self.dtype 的类型是integer或者boolean,那么输出的类型为float32。
- 异常:
TypeError - 如果 self.dtype 的类型不是bool、int8、int32、int64、uint8、float16、float32、float64、double、complex64、complex128其中的一种。
TypeError - 在CPU或者GPU平台中,如果 self.dtype 的类型是integer或者boolean。
- 支持平台:
Ascend
GPU
CPU
样例:
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor >>> x = Tensor(np.array([3.0, 5.0, 7.0]), mindspore.float32) >>> output = Tensor.log2(x) >>> print(output) [1.5849625 2.321928 2.807355 ] >>> x = Tensor(np.array([2, 4, 8]).astype(np.float16)) >>> output = Tensor.log2(x) >>> print(output) [1. 2. 3.]