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

Pytorch torch 参考手册