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

PyTorch torch.renorm function

PyTorch torch.renorm function


PyTorch torch reference manual PyTorch torch reference manual

torch.renorm is a function in PyTorch used to renormalize tensors. It normalizes a tensor according to a specified norm, so that the norm of elements along the specified dimension does not exceed a given value.

Function definition

torch.renorm(input, p, dim, maxnorm)

Parameter Description:


Usage examples

Example

import

torch

Creating tensors

x

=

torch.

tensor

(

[

[

2.0

,

4.0

,

6.0

]

,

[

3.0

,

6.0

,

9.0

]

]

)

Perform L2 norm normalization along dim=1 with a maximum norm of 1

y

=

torch.

renorm

(

x

,

p

=

2

,

dim

=

1

,

maxnorm

=

1

)

print

(

y

)

The output is:

tensor([[0.2673, 0.5345, 0.8018],

        [0.2673, 0.5345, 0.8018]])

Example

import

torch

Creating tensors

x

=

torch.

tensor

(

[

[

1.0

,

2.0

,

3.0

]

]

)

Perform L1 norm normalization along dim=1

y

=

torch.

renorm

(

x

,

p

=

1

,

dim

=

1

,

maxnorm

=

1

)

print

(

y

)

The output is:

tensor([[0.1667, 0.3333, 0.5000]])


PyTorch torch reference manual PyTorch torch reference manual