PyTorch torch.isreal function
PyTorch torch reference manual
torch.isreal is a function in PyTorch used to check for real numbers. It returns a Boolean tensor where each element is True if it is a real number (not a complex number).
Function definition
torch.isreal(input)
Usage examples
Example
import
torch
Create a tensor containing real and complex numbers
x
=
torch.
tensor
(
[
1.0
,
2
+3j
,
4.0
,
5
+1j
]
)
Check for real numbers
result
=
torch.
isreal
(
x
)
(
result
)
The output is:
tensor([True, False, True, False])