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

PyTorch torch.resolve_neg function

PyTorch torch.resolve_neg function


PyTorch torch reference manual PyTorch torch reference manual

torch.resolve_neg is a function in PyTorch used to resolve negative views. If the input tensor is a view of a negated value (that is, a view created by taking the negative), the function returns the actual tensor data.

Function definition

torch.resolve_neg(input)


Usage examples

Example

import

torch

Creating tensors

x

=

torch.

tensor

(

[

1.0

,

2.0

,

3.0

,

4.0

]

)

Get a negative view

x_neg

=

torch.

neg

(

x

)

Resolve the negative view

resolved

=

torch.

resolve_neg

(

x_neg

)

print

(

"Original tensor:"

,

x

)

print

(

"Negative view:"

,

x_neg

)

print

(

"After resolving:"

,

resolved

)

The output is:

原始张量: tensor([1., 2., 3., 4.])

负视图: tensor([-1., -2., -3., -4.])

解析后: tensor([-1., -2., -3., -4.])


PyTorch torch reference manual PyTorch torch reference manual