.conj()

teja_99's avatar
Published Nov 9, 2024
Contribute to Docs

In PyTorch, the .conj() function is used to compute the complex conjugate of each element in a given tensor, returning a new tensor with the computed conjugate values.

Syntax

torch.conj(tensor)
  • tensor: The input tensor for which the complex conjugate will be computed.

Example

The following example illustrates the usage of .conj():

import torch
complex_tensor = torch.tensor([1 + 2j, 3 - 4j, 5 + 0j])
print("Original Complex Tensor:")
print(complex_tensor)
# Applying .conj() on a complex tensor
complex_conj = torch.conj(complex_tensor)
print(f"\nReturn type of .conj() - {type(complex_conj)}")
print("\nComplex Conjugate:")
print(complex_conj)

The above program gives the following output:

Original Complex Tensor:
tensor([1.+2.j, 3.-4.j, 5.+0.j])
Return type of .conj() - <class 'torch.Tensor'>
Complex Conjugate:
tensor([1.-2.j, 3.+4.j, 5.-0.j])

All contributors

Contribute to Docs

Learn PyTorch on Codecademy