PyTorch torch.isreal 函数
torch.isreal 是 PyTorch 中用于检查是否实数的函数。返回一个布尔张量,对于每个元素,如果是实数(不是复数)则为True。
函数定义
torch.isreal(input)
使用示例
实例
import torch
# 创建包含实数和复数的张量
x = torch.tensor([1.0, 2+3j, 4.0, 5+1j])
# 检查是否实数
result = torch.isreal(x)
print(result)
# 创建包含实数和复数的张量
x = torch.tensor([1.0, 2+3j, 4.0, 5+1j])
# 检查是否实数
result = torch.isreal(x)
print(result)
输出结果为:
tensor([True, False, True, False])

Pytorch torch 参考手册