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
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
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
For real numbers, the adjoint is the same as the regular transpose since there’s no complex component to conjugate.
Related posts

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Machine Learning frameworks like PyTorch and Tensorflow is a testament to his versatility and commitment to the craft.