PyTorch torch.is_tensor 函数
PyTorch torch.is_tensor 函数
torch.is_tensor 是 PyTorch 中用于检查对象是否为张量的函数。
函数定义
torch.is_tensor(obj)
使用示例
实例
import torch
# 检查是否为张量
x = torch.tensor([1, 2, 3])
y = [1, 2, 3]
print(torch.is_tensor(x)) # True
print(torch.is_tensor(y)) # False
# 检查是否为张量
x = torch.tensor([1, 2, 3])
y = [1, 2, 3]
print(torch.is_tensor(x)) # True
print(torch.is_tensor(y)) # False