PyTorch torch.adjoint Function
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:
input(Tensor): the input tensor.
Return Value:
torch.Tensor: returns the conjugate transpose of the input tensor.
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
)
(
"Original matrix:"
)
(
A
)
(
"Shape:"
,
A.
shape
)
(
"Conjugate transpose:"
)
(
result
)
(
"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
)
(
"Original matrix:"
)
(
A
)
(
"Conjugate transpose:"
)
(
result
)