Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.frexp function

PyTorch torch.frexp function


PyTorch torch reference manual PyTorch torch reference manual

torch.frexp A function in PyTorch for decomposing a floating-point number into a mantissa and an exponent.

Function definition

torch.frexp(input)


Returns two tensors:


Usage examples

Example

import

torch

Create a floating-point tensor

x

=

torch.

tensor

(

[

8.0

,

4.5

,

2.0

]

)

Decompose into mantissa and exponent

mantissa

,

exponent

=

torch.

frexp

(

x

)

print

(

"Mantissa:"

,

mantissa

)

print

(

"Exponent:"

,

exponent

)

Verify: x = mantissa * 2^exponent

print

(

"Verify:"

,

mantissa *

2

** exponent

)

The output is:

尾数: tensor([0.5000, 0.5625, 0.5000])

指数: tensor([4, 3, 2])

验证: tensor([8., 4.5, 2.])


PyTorch torch reference manual PyTorch torch reference manual