PyTorch torch.is_complex() Method

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

torch.is_tensor()

Leave a Comment