当前位置:网站首页>tensor.eq() tensor.item() tensor.argmax()
tensor.eq() tensor.item() tensor.argmax()
2022-08-09 10:28:00 【白十月】
tensor.eq()
torch.eq(input, other, *, out=None)
对两个张量Tensor进行逐元素的比较,若相同位置的两个元素相同,则返回True;若不同,返回False。
Parameters(参数):
input :必须是一个Tensor,该张量用于比较
other :可以是一个张量Tensor,也可以是一个值value
return(返回值):返回一个Boolean类型的张量,对两个张量Tensor进行逐元素的比较,若相同位置的两个元素相同,则返回True;若不同,返回False。
import torch
x = torch.tensor([[1, 2], [3, 4]])
y = torch.tensor([[1, 1], [3, 3]])
print(x)
print(y)
out = torch.eq(x, y)
print(out)
out1 = torch.eq(x, y).sum()
print(out1)
out2 = torch.eq(x, y).sum().float()
print(out2)
out3 = torch.eq(x, y).sum().item()
print(out3)
输出为:
tensor([[1, 2],
[3, 4]])
tensor([[1, 1],
[3, 3]])
tensor([[ True, False],
[ True, False]])
tensor(2)
tensor(2.)
2
tensor.item()
item() 返回一个数
该方法的功能是以标准的Python数字的形式来返回这个张量的值.这个方法
只能用于只包含一个元素的张量.对于其他的张量,请查看方法tolist().
tensor.argmax()
返回输入张量中所有元素的最大值的索引。
官方文档:https://pytorch.org/docs/stable/generated/torch.argmax.html
import torch
a = torch.randn(3, 4)
torch.argmax(a)
torch.argmax(a,dim=1)
torch.argmax(a,dim=0)
tensor([[-0.0815, 0.8759, -0.1932, 0.6896],
[-1.1432, -0.4114, -0.6331, 0.2309],
[-0.2122, 0.2187, 0.3195, -0.7594]])
tensor(1)
tensor([1, 3, 2])
tensor([0, 0, 2, 0])
边栏推荐
- electron 应用开发优秀实践
- unix环境编程 第十五章 15.6 XSI IPC
- Demand side power load forecasting (Matlab code implementation)
- 分类预测 | MATLAB实现CNN-LSTM(卷积长短期记忆神经网络)多特征分类预测
- 自启服务mock联调跨域问题
- 学习NET-SNMP之二-----------VisualStudio编译Net-SNMP
- xmms播放器加了播放列表的管理功能
- 抛出一个问题? Mysql环境下进行Count操作执行的时候速度很慢_需手动给主键添加索引---MySql优化001
- xmms的均衡器试验成功 音效相当不错 比rockbox可能还要好
- 踩坑scrollIntoView
猜你喜欢
随机推荐
unix系统编程 第十五章 15.2管道
[贴装专题] 基于多目视觉的手眼标定
排序1:冒泡排序
编解码(seq2seq)+注意机制(attention) 详细讲解
[项目配置] 配置Qt函数库和ui界面库的封装并调用的项目
[相机配置] 海康相机丢包配置环境
By asking where the variables are stored, the shepherd boy laughed and said to use pointers, Go lang1.18 introductory refining tutorial, from Bai Ding to Hongru, the use of go lang type pointers (Poin
unix环境编程 第十四章 14.8 存储映射I/O
Apache Log4j 2 远程代码执行漏洞详解
自启服务mock联调跨域问题
踩坑scrollIntoView
第二周作业
MySQL备份与恢复
函数组件和类组件和dva视图更新问题
Nodejs服务端
面试官:MySQL 中 update 更新,数据与原数据相同时会执行吗?大部分人答不上来!
相伴成长,彼此成就 用友U9 cloud做好制造业数智化升级的同路人
Tom Morgan | Twenty-One Rules of Life
如何快速打通镜像发布流程?
开源SPL,WebService/Restful广泛应用于程序间通讯,如微服务、数据交换、公共或私有的数据服务等。