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

PyTorch torch.adjoint Function

PyTorch torch.adjoint Function


PyTorch torch reference manual PyTorch torch reference manual

torch.adjoint is a function in PyTorch used to compute the conjugate transpose (adjoint) of a matrix. For real matrices, it is equivalent to the transpose; for complex matrices, it returns the transpose and takes the conjugate of each element.

Function definition

torch.adjoint(input)

Parameters:

Return Value:


Usage examples

Example - real matrix

import

torch

Create a real matrix

A

=

torch.

tensor

(

[

[

1

,

2

,

3

]

,

[

4

,

5

,

6

]

]

)

Compute the conjugate transpose

result

=

torch.

adjoint

(

A

)

print

(

"Original matrix:"

)

print

(

A

)

print

(

"Shape:"

,

A.

shape

)

print

(

"Conjugate transpose:"

)

print

(

result

)

print

(

"Shape:"

,

result.

shape

)

The output is:

原矩阵:

tensor([[1, 2, 3],

        [4, 5, 6]])

形状: torch.Size([2, 3])

Conjugate transpose:

tensor([[1, 4],

        [2, 5],

        [3, 6]])

形状: torch.Size([3, 2])

Example - complex matrix

import

torch

Create a complex matrix

A

=

torch.

tensor

(

[

[

1

+1j

,

2

+2j

]

,

[

3

+3j

,

4

+4j

]

]

)

Compute the conjugate transpose

result

=

torch.

adjoint

(

A

)

print

(

"Original matrix:"

)

print

(

A

)

print

(

"Conjugate transpose:"

)

print

(

result

)


PyTorch torch reference manual PyTorch torch reference manual