PyTorch .frexp()
Anonymous contributor
Published Aug 29, 2025
Contribute to Docs
In PyTorch, the .frexp() function takes a tensor as input and returns a tuple storing two tensors: mantissa and exponent. The range of mantissa is the open interval (-1, 1). The original input can be reconstructed as :
$$\text{input} = \text{mantissa}\times 2^{\text{exponent}}$$
Syntax
torch.frexp(input, *, out=None) -> (Tensor mantissa, Tensor exponent)
Parameters:
input: The input tensor.out(Optional): A tuple of two tensors(mantissa, exponent)that will store the result. If provided, the output is written in place.
Return value:
It returns a tuple containing two tensors - mantissa and exponent.
Example
This example uses the .frexp() function on a tensor. The result contains two tensors mantissa and exponent (which can give numerical stability when floating point numbers are too small or too large):
import torchx = torch.tensor([1. , 4. , 5. , 9. ])mantissa, exponent = torch.frexp(x)print(mantissa)print(exponent)
The output of this code is:
tensor([0.5000, 0.5000, 0.6250, 0.5625])tensor([1, 3, 3, 4], dtype=torch.int32)
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn PyTorch on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn how to use PyTorch to build, train, and test artificial neural networks in this course.
- Intermediate.3 hours