torch.eq、torch.ne、torch.gt、torch.lt、torch.ge、torch.le 等函数详解

torch.eq、torch.netorch.gttorch.lttorch.ge、torch.le

以上全是简写 参数是input, other, out=None 逐元素比较input和other 返回是torch.BoolTensor

复制代码
import torch

a=torch.tensor([[1, 2], [3, 4]])
b=torch.tensor([[1, 2], [4, 3]])

print(torch.eq(a,b))#equals
# tensor([[ True,  True],
#         [False, False]])

print(torch.ne(a,b))#not equal to
# tensor([[False, False],
#         [ True,  True]])

print(torch.gt(a,b))#greater than
# tensor([[False, False],
#         [False,  True]])

print(torch.lt(a,b))#less than
# tensor([[False, False],
#         [ True, False]])

print(torch.ge(a,b))#greater than or equal to
# tensor([[ True,  True],
#         [False,  True]])

print(torch.le(a,b))#less than or equal to
# tensor([[ True,  True],
#         [ True, False]])
相关推荐
Python私教18 分钟前
Django 接入 AI 大模型实战:从零做一个流式聊天网站
人工智能·python·django
Python私教22 分钟前
Django 接入 MCP 实战:让 AI 安全调用数据库和业务接口
人工智能·python·django
Python私教27 分钟前
Django 搭建 AI 本地知识库:文档上传、向量检索与智能问答
人工智能·python·django
always_TT1 小时前
【Python 日志记录:logging 模块入门】
开发语言·python·php
LaughingZhu2 小时前
Product Hunt 每日热榜 | 2026-08-01
人工智能·深度学习·神经网络·搜索引擎·百度
lipku3 小时前
数字人直播开源项目LiveStream
python·开源·数字人·数字人直播
阿童木写作4 小时前
Python实现亚马逊商品图批量智能抠图教程
人工智能·python
axinawang4 小时前
第24课:while循环的应用
python
三亚兴嘉装饰4 小时前
三亚服装店装修
python
小柯南敲键盘4 小时前
速卖通AI图片翻译API集成实战
人工智能·python