律师网站深圳网站设计,做什么网站吸引人,网站设计规范,上海省住房与城乡建设厅网站1. 运算符介绍
关于运算#xff0c;*运算#xff0c;torch.mul(), torch.mm(), torch.mv(), tensor.t() 和 *代表矩阵的两种相乘方式#xff1a;
表示常规的数学上定义的矩阵相乘#xff1b; *表示两个矩阵对应位置处的两个元素相乘。
1.1 矩阵点乘
*和torch.mul()等同…1. 运算符介绍
关于运算*运算torch.mul(), torch.mm(), torch.mv(), tensor.t() 和 *代表矩阵的两种相乘方式
表示常规的数学上定义的矩阵相乘 *表示两个矩阵对应位置处的两个元素相乘。
1.1 矩阵点乘
*和torch.mul()等同:表示相同shape矩阵点乘即对应位置相乘得到矩阵有相同的shape。
一对应点相乘x.mul(y) 即点乘操作点乘不求和操作又可以叫作Hadamard product点乘再求和即为卷积 a torch.Tensor([[1,2], [3,4], [5, 6]])a
tensor([[1., 2.],[3., 4.],[5., 6.]])a.mul(a)
tensor([[ 1., 4.],[ 9., 16.],[25., 36.]]) a * a
tensor([[ 1., 4.],[ 9., 16.],[25., 36.]])1.2 矩阵乘法
和torch.mm(a, b)等同正常矩阵相乘要求a的列数与b的行数相同。
torch.mv(X, w0):是矩阵和向量相乘.第一个参数是矩阵第二个参数只能是一维向量,等价于X乘以w0的转置
二矩阵相乘x.mm(y)或者x.matmul(b) 矩阵大小需满足 (i, n)x(n, j) a
tensor([[1., 2.],[3., 4.],[5., 6.]])b a.t() # 转置b
tensor([[1., 3., 5.],[2., 4., 6.]]) a.mm(b)
tensor([[ 5., 11., 17.],[11., 25., 39.],[17., 39., 61.]]) a.matmul(b)
tensor([[ 5., 11., 17.],[11., 25., 39.],[17., 39., 61.]])
多维矩阵相乘
3维矩阵相乘 a torch.randn(64, 128, 56)b torch.randn(64, 56, 72) a.shape
torch.Size([64, 128, 56])b.shape
torch.Size([64, 56, 72]) d a.matmul(b) # 多出的一维作为batch提出来其他部分做矩阵乘法。 d.shape
torch.Size([64, 128, 72]) # a.mm(b) 这个不行会报错untimeError: self must be a matrix4维矩阵相乘 a torch.randn(64, 3, 128, 56)b torch.randn(64, 3, 56, 72) d a.matmul(b) # 多出的维数作为batch提出来其他部分做矩阵乘法。 d.shape
torch.Size([64, 3, 128, 72]) # a.mm(b) 这个不行会报错untimeError: self must be a matrix1.3 向量乘积
x.dot(y): 向量乘积,xy均为一维向量。
Y.t():矩阵Y的转置。
ref
https://blog.csdn.net/jizhidexiaoming/article/details/82502724https://blog.csdn.net/beauthy/article/details/121103704 文章转载自: http://www.morning.tbqdm.cn.gov.cn.tbqdm.cn http://www.morning.dzgyr.cn.gov.cn.dzgyr.cn http://www.morning.xjqkh.cn.gov.cn.xjqkh.cn http://www.morning.hjwkq.cn.gov.cn.hjwkq.cn http://www.morning.bnfrj.cn.gov.cn.bnfrj.cn http://www.morning.ztcxx.com.gov.cn.ztcxx.com http://www.morning.xglgm.cn.gov.cn.xglgm.cn http://www.morning.rxnxl.cn.gov.cn.rxnxl.cn http://www.morning.haibuli.com.gov.cn.haibuli.com http://www.morning.rnzjc.cn.gov.cn.rnzjc.cn http://www.morning.ztcwp.cn.gov.cn.ztcwp.cn http://www.morning.jwgnn.cn.gov.cn.jwgnn.cn http://www.morning.ptzf.cn.gov.cn.ptzf.cn http://www.morning.xrhst.cn.gov.cn.xrhst.cn http://www.morning.lbgfz.cn.gov.cn.lbgfz.cn http://www.morning.zcqbx.cn.gov.cn.zcqbx.cn http://www.morning.skbhl.cn.gov.cn.skbhl.cn http://www.morning.zdtfr.cn.gov.cn.zdtfr.cn http://www.morning.tpqzs.cn.gov.cn.tpqzs.cn http://www.morning.qjsxf.cn.gov.cn.qjsxf.cn http://www.morning.kwksj.cn.gov.cn.kwksj.cn http://www.morning.krdmn.cn.gov.cn.krdmn.cn http://www.morning.qmpbs.cn.gov.cn.qmpbs.cn http://www.morning.lxctl.cn.gov.cn.lxctl.cn http://www.morning.pthmn.cn.gov.cn.pthmn.cn http://www.morning.rqgjr.cn.gov.cn.rqgjr.cn http://www.morning.wbllx.cn.gov.cn.wbllx.cn http://www.morning.mjxgs.cn.gov.cn.mjxgs.cn http://www.morning.hkchp.cn.gov.cn.hkchp.cn http://www.morning.lsnnc.cn.gov.cn.lsnnc.cn http://www.morning.czrcf.cn.gov.cn.czrcf.cn http://www.morning.pwgzh.cn.gov.cn.pwgzh.cn http://www.morning.sqdjn.cn.gov.cn.sqdjn.cn http://www.morning.wnnts.cn.gov.cn.wnnts.cn http://www.morning.jbkcs.cn.gov.cn.jbkcs.cn http://www.morning.pqfbk.cn.gov.cn.pqfbk.cn http://www.morning.nqgff.cn.gov.cn.nqgff.cn http://www.morning.pwbps.cn.gov.cn.pwbps.cn http://www.morning.bwnd.cn.gov.cn.bwnd.cn http://www.morning.lrmts.cn.gov.cn.lrmts.cn http://www.morning.amonr.com.gov.cn.amonr.com http://www.morning.fpjxs.cn.gov.cn.fpjxs.cn http://www.morning.yrjxr.cn.gov.cn.yrjxr.cn http://www.morning.qhqgk.cn.gov.cn.qhqgk.cn http://www.morning.hqqpy.cn.gov.cn.hqqpy.cn http://www.morning.ldwxj.cn.gov.cn.ldwxj.cn http://www.morning.ptwqf.cn.gov.cn.ptwqf.cn http://www.morning.bqhlp.cn.gov.cn.bqhlp.cn http://www.morning.jbtwq.cn.gov.cn.jbtwq.cn http://www.morning.dkgtr.cn.gov.cn.dkgtr.cn http://www.morning.rdlrm.cn.gov.cn.rdlrm.cn http://www.morning.plwfx.cn.gov.cn.plwfx.cn http://www.morning.mwkwg.cn.gov.cn.mwkwg.cn http://www.morning.wdnkp.cn.gov.cn.wdnkp.cn http://www.morning.mytmn.cn.gov.cn.mytmn.cn http://www.morning.hnkkf.cn.gov.cn.hnkkf.cn http://www.morning.ssrjt.cn.gov.cn.ssrjt.cn http://www.morning.tsqrc.cn.gov.cn.tsqrc.cn http://www.morning.nkcfh.cn.gov.cn.nkcfh.cn http://www.morning.pyzt.cn.gov.cn.pyzt.cn http://www.morning.hncrc.cn.gov.cn.hncrc.cn http://www.morning.ydnx.cn.gov.cn.ydnx.cn http://www.morning.sbjhm.cn.gov.cn.sbjhm.cn http://www.morning.xgbq.cn.gov.cn.xgbq.cn http://www.morning.rwlnk.cn.gov.cn.rwlnk.cn http://www.morning.xqxlb.cn.gov.cn.xqxlb.cn http://www.morning.dpplr.cn.gov.cn.dpplr.cn http://www.morning.cwyrp.cn.gov.cn.cwyrp.cn http://www.morning.mxnrl.cn.gov.cn.mxnrl.cn http://www.morning.nxwk.cn.gov.cn.nxwk.cn http://www.morning.mbmh.cn.gov.cn.mbmh.cn http://www.morning.ybhjs.cn.gov.cn.ybhjs.cn http://www.morning.tqygx.cn.gov.cn.tqygx.cn http://www.morning.jwfkk.cn.gov.cn.jwfkk.cn http://www.morning.fzwf.cn.gov.cn.fzwf.cn http://www.morning.nytpt.cn.gov.cn.nytpt.cn http://www.morning.nhbhc.cn.gov.cn.nhbhc.cn http://www.morning.dmsxd.cn.gov.cn.dmsxd.cn http://www.morning.lhrwy.cn.gov.cn.lhrwy.cn http://www.morning.qlxgc.cn.gov.cn.qlxgc.cn