PyTorch torch.is_complex Function
PyTorch torch Reference Manual
torch.is_complexIt is a function in PyTorch used to check whether the tensor data type is a complex type.
Function Definition
torch.is_complex(input)
Usage Example
Example
import torch
# Check real tensor
x = torch.tensor([1.0, 2.0, 3.0])
print("Real:", torch.is_complex(x))
# Check complex tensor
y = torch.tensor([1+2j, 3+4j])
print("Complex:", torch.is_complex(y))
# Check real tensor
x = torch.tensor([1.0, 2.0, 3.0])
print("Real:", torch.is_complex(x))
# Check complex tensor
y = torch.tensor([1+2j, 3+4j])
print("Complex:", torch.is_complex(y))
The output result is:
实数: False 复数: True
Other Extensions