PyTorch torch.is_complex() method is “used to check if a given tensor has a complex data type.” PyTorch introduced complex number support in version 1.6.0, and this function is a utility to help users determine if their tensor is of a complex type.
Syntax
torch.is_complex(input)
Parameters
input (Tensor): It is the input tensor.
Example
import torch
tensor = torch.tensor([1 + 1j, 2 + 2j])
print(torch.is_complex(tensor))
tensor2 = torch.tensor([1, 2])
print(torch.is_complex(tensor2))
Output
True
False
That’s it!
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.