Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.is_complex function

PyTorch torch.is_complex function


PyTorch torch reference manual 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

]

)

print

(

"Real:"

,

torch.

is_complex

(

x

)

)

Check a complex tensor

y

=

torch.

tensor

(

[

1

+2j

,

3

+4j

]

)

print

(

"Complex:"

,

torch.

is_complex

(

y

)

)

The output is:

实数: False

复数: True


PyTorch torch reference manual PyTorch torch reference manual