PyTorch torch.ldexp 函数

约 370 字 更新于 2026-11-18 5iyo.com

PyTorch torch.ldexp 函数


torch.ldexp 是 PyTorch 中用于将尾数与2的指数次幂相乘的函数,是 frexp 的逆操作。

函数定义

torch.ldexp(input, other, out=None)

使用示例

实例

import torch

# 使用 frexp 分解
x = torch.tensor([8.0, 4.5, 2.0])
mantissa, exponent = torch.frexp(x)

# 使用 ldexp 重建
reconstructed = torch.ldexp(mantissa, exponent)
print("重建值:", reconstructed)

输出结果为:

重建值: tensor([8., 4.5, 2.])