maxframe.tensor.frexp#

maxframe.tensor.frexp(x, out1=None, out2=None, out=None, where=None, **kwargs)[源代码]#

将 x 的元素分解为尾数和二的幂次。

返回 (mantissa, exponent),其中 x = mantissa * 2**exponent`。 尾数位于开区间 (-1, 1) 内,而二的幂次是一个有符号整数。

参数:
  • x (array_like) -- 要分解的数字张量。

  • out1 (Tensor, optional) -- 用于存储尾数的输出张量。必须与 x 具有相同的形状。

  • out2 (Tensor, optional) -- 用于存储指数的输出张量。必须与 x 具有相同的形状。

  • out (Tensor, None, or tuple of Tensor and None, optional) -- 用于存储结果的位置。如果提供,则其形状必须可以广播到输入形状。如果未提供或为 None,则返回一个新分配的张量。元组(仅可作为关键字参数)的长度必须等于输出的数量。

  • where (array_like, optional) -- 值为 True 表示在该位置计算 ufunc,值为 False 表示保留输出中的值不变。

  • **kwargs

返回:

(mantissa, exponent) -- mantissa 是一个值在 -1 和 1 之间的浮点数组。exponent 是一个表示 2 的幂次的整数数组。

返回类型:

tuple of tensors, (float, int)

参见

ldexp

计算 y = x1 * 2**x2,即 frexp 的逆运算。

备注

不支持复数数据类型,会引发 TypeError。

示例

>>> import maxframe.tensor as mt
>>> x = mt.arange(9)
>>> y1, y2 = mt.frexp(x)
>>> y1_result, y2_result = mt.ExecutableTuple([y1, y2]).execute()
>>> y1_result
array([ 0.   ,  0.5  ,  0.5  ,  0.75 ,  0.5  ,  0.625,  0.75 ,  0.875,
        0.5  ])
>>> y2_result
array([0, 1, 2, 2, 3, 3, 3, 3, 4])
>>> (y1 * 2**y2).execute()
array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.])