PyTorch torch.adjoint() Method

PyTorch torch.adjoint() method “returns a view of the tensor conjugated and with the last two dimensions transposed.”

Syntax

torch.adjoint(Tensor)

Parameters

Tensor: It is an input tensor.

Example 1: Basic usage with a 2D complex tensor

import torch

tensor_1 = torch.tensor([[1 + 1j, 2 + 2j], [3 + 3j, 4 + 4j]])
adjoint_1 = torch.adjoint(tensor_1)

print("Original Tensor:")
print(tensor_1)
print("\nAdjoint Tensor:")
print(adjoint_1)

Output

Basic usage with a 2D complex tensor

Example 2: Using the method with higher-dimensional tensors

import torch

tensor_2 = torch.tensor([
  [[1 + 1j, 2 + 2j], [3 + 3j, 4 + 4j]],
  [[5 + 5j, 6 + 6j], [7 + 7j, 8 + 8j]]
])
adjoint_2 = torch.adjoint(tensor_2)

print("Original Tensor:")
print(tensor_2)
print("\nAdjoint Tensor:")
print(adjoint_2)

Output

Using the method with higher-dimensional tensors

Example 3: Using the method with real numbers

import torch

tensor_3 = torch.tensor([[1, 2], [3, 4]])
adjoint_3 = torch.adjoint(tensor_3)

print("Original Tensor:")
print(tensor_3)
print("\nAdjoint Tensor:")
print(adjoint_3)

Output

Using the method with real numbers

For real numbers, the adjoint is the same as the regular transpose since there’s no complex component to conjugate.

Related posts

torch.polar()

torch.dequantize()

torch.eye()

Leave a Comment