PyTorch torch.ldexp Function
Pytorch torch Reference Manual
torch.ldexpIt is a function in PyTorch used to multiply the mantissa by 2 raised to the power of the exponent, and is the inverse operation of frexp.
Function Definition
torch.ldexp(input, other, out=None)
Usage Examples
Example
import torch
# Decompose using frexp
x = torch.tensor([8.0, 4.5, 2.0])
mantissa, exponent = torch.frexp(x)
# Reconstruct using ldexp
reconstructed = torch.ldexp(mantissa, exponent)
print("Reconstructed value:", reconstructed)
# Decompose using frexp
x = torch.tensor([8.0, 4.5, 2.0])
mantissa, exponent = torch.frexp(x)
# Reconstruct using ldexp
reconstructed = torch.ldexp(mantissa, exponent)
print("Reconstructed value:", reconstructed)
The output result is:
重建值: tensor([8., 4.5, 2.])
Other Extensions