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

Pytorch torch 参考手册