当前位置: 首页 > wzjs >正文

网上有做任务赚钱的网站有哪些微信管理系统软件

网上有做任务赚钱的网站有哪些,微信管理系统软件,网站开发需要工具,丽江网站建设 莱芜文章目录 各种乘法操作广播机制torch.matmultorch.multorch.mmtorch.bmmdot() 各种乘法操作 torch.matmul 可广播,确保(…,N,M),(…,M,P) --> (…,N,P) 【前面其他维广播成相同维度】 torch.mul 可广播,保证维度相同&#xf…

文章目录

  • 各种乘法操作
  • 广播机制
  • torch.matmul
  • torch.mul
  • torch.mm
  • torch.bmm
  • dot()
  • @

各种乘法操作

torch.matmul 可广播,确保(…,N,M),(…,M,P) --> (…,N,P) 【前面其他维广播成相同维度】

torch.mul 可广播,保证维度相同,然后逐个元素相乘

torch.mm 不可广播,(M×N) × (N×P) → (M×P),二维矩阵相乘
torch.mm(a,b) == a@b == torch.matmul(a,b)

torch.bmm 不可广播,(B×M×N) × (B×N×P) → (B×M×P),二维矩阵相乘

dot() 必须保持维度一致,相乘相加
在这里插入图片描述

@ 等价于 torch.matmul()

广播机制

广播的执行过程:
1.如果维度个数不同,则在维度较少的左边补1,使得维度的个数相同。

2.各维度的维度大小不同时,如果有维度为1的,直接将该维拉伸至维度相同

torch.matmul

vector * vector = 相加相乘,最后得到一个数.

在 PyTorch 中,torch.matmul(或用 @ 运算符)支持 广播式矩阵乘法 。它的基本规则是:
如果 a.shape == (…, M, N), b.shape == (…, N, P)
那么 torch.matmul(a, b).shape == (…, M, P)
其中前面的 … 表示任意数量的前导维度,只要它们可以广播对齐即可。

#vector * vector = 相加相乘,最后得到一个数
a = torch.randn(3)
b = torch.randn(3)
c = torch.matmul(a,b)
"""
a: tensor([ 2.6767, -0.8028,  4.1741])
b: tensor([-1.0552,  0.2841,  0.8013])
torch.matmul: tensor(0.2923)
"""
#matrix * vector = 矩阵相乘,matrix第二维需要与vector维度相同
a = torch.randn(3,4)
b = torch.randn(4)
c = torch.matmul(a,b)
"""
a: tensor([[-1.2726,  0.6925, -0.3536, -0.2233],[-0.5659,  1.5294,  0.1152, -0.9903],[-0.2644,  0.5090,  0.7059,  0.2046]])
b: tensor([ 0.7085, -0.0952,  1.6654, -0.8139])
torch.matmul: tensor([-1.3747,  0.4513,  0.7733])
****************************************************
"""
# batched matrix x broadcasted vector
a = torch.randn(10, 3, 4)
b = torch.randn(4)
c = torch.matmul(a,b)
"""
在 PyTorch 中,torch.matmul(或用 @ 运算符)支持 广播式矩阵乘法 。它的基本规则是:
如果 a.shape == (..., M, N)
b.shape == (..., N, P)
那么 torch.matmul(a, b).shape == (..., M, P)
其中前面的 ... 表示任意数量的前导维度,只要它们可以广播对齐即可。
"""# batched matrix x batched matrix
a = torch.randn(10,1,3,4)
b = torch.randn(10,3,4,5)
c = torch.matmul(a,b)
"""
a: torch.Size([10, 1, 3, 4])
b: torch.Size([10, 3, 4, 5])
torch.matmul: torch.Size([10, 3, 3, 5])
"""
a = torch.randn(10,3,4)
b = torch.randn(10,4,5)
c = torch.matmul(a,b)
# torch.matmul: torch.Size([10, 3, 5])a = torch.randn(10,1,3,4)
b = torch.randn(10,4,5)
c = torch.matmul(a,b)
#  c:torch.Size([10, 1, 3, 5])# batched matrix x broadcasted matrix
a = torch.randn(10,3,4)
b = torch.randn(4, 5)
c = torch.matmul(a,b)
#  c:torch.Size([10, 3, 5])

torch.mul

若a是tensor,b是标量,则torch.mul(a, b)=b乘a中每个元素,得到与a一样的tensor;

若a是tensor,b是tensor,则torch.mul(a, b)会先对a、b进行广播,保持a、b维数一致,然后实现a和b elem-wise相乘;

import torch
a = torch.randn((2,3))
print('a:',a) 
# a: tensor([[ 0.5374,  0.5964, -0.9717], [ 0.8812,  0.0650,  0.5432]])
b = 100
c = torch.mul(a,b)
print('torch.mul:',c)
# torch.mul: tensor([[ 53.7366,  59.6445, -97.1669], [ 88.1228,   6.5001,  54.3242]])b = torch.randn((1,3)) #b的第二维度与a的第二维度若其中有一个不为1,则二者必须相等
print('b:',b)
# b: tensor([[-0.5949, -1.2634,  0.5233]])
c = torch.mul(a,b)
print('torch.mul:',c)
# 0.5374*-0.5949=-0.3197
# torch.mul: tensor([[-0.3197, -0.7535, -0.5084], [-0.5243, -0.0821,  0.2843]])a = torch.randn(4, 1)
b = torch.randn(1,4)
c = torch.mul(a,b) # (4,4)
print('torch.mul:',c)
"""
a: tensor([[ 1.1754],[ 0.0786],[-0.4219],[ 0.4158]])
b: tensor([[1.4896, 0.3157, 0.0024, 0.6818]])
###c[0][0]=1.1754*1.4896=1.7509e+00
###c[-1][-1]= 0.4158*0.6818=2.8348e-01
torch.mul: tensor([[ 1.7509e+00,  3.7115e-01,  2.7752e-03,  8.0140e-01],[ 1.1702e-01,  2.4805e-02,  1.8548e-04,  5.3562e-02],[-6.2843e-01, -1.3321e-01, -9.9606e-04, -2.8763e-01],[ 6.1936e-01,  1.3129e-01,  9.8170e-04,  2.8348e-01]])
"""

torch.mm

矩阵相乘,不会进行广播,必须满足矩阵相乘维数条件,两矩阵最多是2维

a = torch.randn(2, 3)
b = torch.randn(3, 3)
c = torch.mm(a,b)
print('torch.mm:',c.shape)
# torch.mm: torch.Size([2, 3])

torch.bmm

a = torch.randn(10,2, 3)
b = torch.randn(10,3, 3)
c = torch.bmm(a,b)
print('torch.bmm:',c.shape)
# torch.bmm: torch.Size([10, 2, 3])

dot()

在 PyTorch 中,torch.dot() 是一个用于计算 两个一维张量(向量)的点积(dot product) 的函数。它与矩阵乘法不同,仅适用于一维张量。

import torcha = torch.tensor([2, 3])
b = torch.tensor([4, 5])result = torch.dot(a, b)
print(result)  # 输出: 2*4 + 3*5 = 8 + 15 = 23
# 正确代码
a = torch.randn(3)
b = torch.randn(3)
c = torch.dot(a, b)  # 合法
# 错误代码
a = torch.randn(2, 3)
b = torch.randn(3)
c = torch.dot(a, b)  # 报错:Expected both vectors to be 1D!

在这里插入图片描述

@

在这里插入图片描述

http://www.dtcms.com/wzjs/167985.html

相关文章:

  • 做gif网站企业如何建立网站
  • 宁波专业网站建设公司网站宣传方法
  • 制作网站一年多少钱今天上海重大新闻事件
  • 装修行业 网站建设天猫关键词排名怎么控制
  • wordpress免费简约主题天津seo代理商
  • 厦门网站制作费用明细网络销售好做吗
  • 东莞 网站建设seo怎么才能优化好
  • yellow片免费观看高清在线中国网民博客 seo
  • 网站商城app 建设方案谷歌应用商店app下载
  • 元氏网站建设长沙网站seo服务
  • 婚纱摄影网站网站制作教程
  • 汕头建站服务网络销售怎么找客源
  • 国内免备案网站空间网络营销心得体会1000字
  • 云服务器建设网站看b站视频下载软件
  • 网站建设有哪些风险想要网站推广页
  • 做网站和优化营销存在的问题及改进
  • 外贸网店建站模板百度账号查询
  • 晋中住房与城乡建设厅网站李勇seo博客
  • 北京最新疫情数据武汉seo和网络推广
  • 网站分析免费域名申请网站大全
  • 设计网站都有什么作用是什么数据分析师培训需要多少钱
  • 装修公司全屋整装惠州seo招聘
  • linux系统怎么做网站最新搜索引擎排名
  • phpweb成品网站建站超市系统搜索词热度查询
  • wordpress操作鞍山seo优化
  • 龙华网站建设的基本步骤上海seo推广公司
  • 花生壳做网站有流量限制地推接单平台网
  • 全美网站建设重庆seo
  • 360建筑网证书广州seo全网营销
  • 做推广优化的网站有哪些武汉seo网络营销推广