PyTorch torch.isreal Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.isrealIt is a function in PyTorch used to check whether a value is a real number. It returns a boolean tensor where, for each element, the value is True if it is a real number (not a complex number).

Function Definition

torch.isreal(input)

Usage Example

Example

import torch

# Create a tensor containing real and complex numbers
x = torch.tensor([1.0, 2+3j, 4.0, 5+1j])

# Check whether it is a real number
result = torch.isreal(x)
print(result)

The output result is:

tensor([True, False, True, False])

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions