当前位置:网站首页>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])
边栏推荐
- 排序1:冒泡排序
- Probably 95% of the people are still making PyTorch mistakes
- Master-slave postition changes cannot be locked_Slave_IO_Running shows No_Slave_Sql_Running shows No---Mysql master-slave replication synchronization 002
- basic operator
- MySQL全文索引
- The GNU Privacy Guard
- 【原创】解决阿里云oss-browser.exe双击没反应打不开,提供一种解决方案
- 【Linux】宝塔面板设置MySQL慢查询日志,未走索引日志
- 踩坑scrollIntoView
- Tom Morgan | Twenty-One Rules of Life
猜你喜欢
随机推荐
Qt 国际化翻译
1002 写出这个数 (20 分)
unix环境编程 第十四章 14.8 存储映射I/O
循环嵌套以及列表的基本操作
深度学习--神经网络(基础讲解)
UNIX Environment Programming Chapter 15 15.5FIFO
StratoVirt 中的虚拟网卡是如何实现的?
机器学习--线性回归(Linear Regression)
xmms已经发布到v1.3了,好久没写博客了
[Halcon&定位] 解决Roi区域外的模板匹配成功
第二周作业
SQL Server查询优化
3D打印了这个杜邦线理线神器,从此桌面再也不乱了
OneNote 教程,如何在 OneNote 中搜索和查找笔记?
Apache Log4j 2 远程代码执行漏洞详解
Redis cache update strategy actively
使用cpolar远程连接群晖NAS(创建临时链接)
Umi Hooks
主从postition变化无法锁定_Slave_IO_Running显示No_Slave_Sql_Running显示No---Mysql主从复制同步002
关于页面初始化