PyTorch torch.not_equal 函数
torch.not_equal 是 PyTorch 中用于逐元素比较不等于的函数。返回第一个张量元素不等于第二个张量对应元素的位置为True的张量。
函数定义
torch.not_equal(input, other)
使用示例
实例
import torch
# 创建两个张量
x = torch.tensor([1, 2, 3])
y = torch.tensor([1, 4, 3])
# 逐元素比较不等于
result = torch.not_equal(x, y)
print(result)
# 创建两个张量
x = torch.tensor([1, 2, 3])
y = torch.tensor([1, 4, 3])
# 逐元素比较不等于
result = torch.not_equal(x, y)
print(result)
输出结果为:
tensor([False, True, False])

Pytorch torch 参考手册