PyTorch torch.is_complex function
PyTorch torch reference manual
torch.is_complex A function in PyTorch for checking whether a tensor's data type is a complex type.
Function definition
torch.is_complex(input)
Usage examples
Example
import
torch
Check a real-valued tensor
x
=
torch.
tensor
(
[
1.0
,
2.0
,
3.0
]
)
(
"Real:"
,
torch.
is_complex
(
x
)
)
Check a complex tensor
y
=
torch.
tensor
(
[
1
+2j
,
3
+4j
]
)
(
"Complex:"
,
torch.
is_complex
(
y
)
)
The output is:
实数: False
复数: True