Skip to content
This repository was archived by the owner on Feb 27, 2026. It is now read-only.

Commit ea4e596

Browse files
[Term Entry] PyTorch Tensor Operations: .frexp()
* Create frexp.md * minor changes * Update frexp.md ---------
1 parent f99e92a commit ea4e596

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

  • content/pytorch/concepts/tensor-operations/terms/frexp
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
Title: '.frexp()'
3+
Description: 'Decomposes input into mantissa and exponent tensors.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Machine Learning'
7+
Tags:
8+
- 'Functions'
9+
- 'Machine Learning'
10+
- 'Python'
11+
- 'Tensor'
12+
CatalogContent:
13+
- 'intro-to-py-torch-and-neural-networks'
14+
- 'paths/computer-science'
15+
---
16+
17+
In PyTorch, the **`.frexp()`** function takes a [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors) 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 :
18+
19+
$$\text{input} = \text{mantissa}\times 2^{\text{exponent}}$$
20+
21+
## Syntax
22+
23+
```pseudo
24+
torch.frexp(input, *, out=None) -> (Tensor mantissa, Tensor exponent)
25+
```
26+
27+
**Parameters:**
28+
29+
- `input`: The input tensor.
30+
- `out` (Optional): A tuple of two tensors `(mantissa, exponent)` that will store the result. If provided, the output is written in place.
31+
32+
**Return value:**
33+
34+
It returns a tuple containing two tensors - mantissa and exponent.
35+
36+
## Example
37+
38+
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):
39+
40+
```py
41+
import torch
42+
43+
x = torch.tensor([1. , 4. , 5. , 9. ])
44+
mantissa, exponent = torch.frexp(x)
45+
46+
print(mantissa)
47+
print(exponent)
48+
```
49+
50+
The output of this code is:
51+
52+
```shell
53+
tensor([0.5000, 0.5000, 0.6250, 0.5625])
54+
tensor([1, 3, 3, 4], dtype=torch.int32)
55+
```

0 commit comments

Comments
 (0)