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

PyTorch torch.ldexp function

PyTorch torch.ldexp function


PyTorch torch reference manual PyTorch torch reference manual

torch.ldexp is a function in PyTorch used to multiply the mantissa by 2 raised to the power of the exponent; it 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 values:"

,

reconstructed

)

The output is:

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


PyTorch torch reference manual PyTorch torch reference manual