zoukankan      html  css  js  c++  java
  • tensor乘运算

    **torch.mul(a, b) **是矩阵 对应位相乘,即点乘操作, a和b的维度必须相等,a的维度是(1,2), 则b的维度必须是(1,2), 返回还是(1,2)的矩阵

    torch.mm(a,b)是矩阵a和b矩阵相乘,a的维度是(1,2),b的维度是(2,3),返回是(1,3)的矩阵

    torch.bmm(a,b)是矩阵a和b在维度1、2上矩阵相乘,一般要求是 三维矩阵,a的维度是(64,1,2),b的维度是(64,2,3)返回的是(64,1,3)矩阵

    import torch
    
    
    if __name__ == "__main__":
        x = torch.ones(1, 2)
        y = torch.ones(1, 2) * 2
        z = torch.mul(x, y)
        print("torch.mul() example ")
        print("x.shape is ", x.shape) 
        print("y.shape is ", y.shape)
        print("z.shape is ", z.shape) ## [1, 2]
    
        x = torch.ones(1, 2)
        y = torch.ones(2, 3) 
        z = torch.mm(x, y)
        print("torch.mm() example ")
        print("x.shape is ", x.shape)
        print("y.shape is ", y.shape)
        print("z.shape is ", z.shape) ## [1,3]
    
        x = torch.randn(64, 1, 2)
        y = torch.randn(64, 2, 3)
        z = torch.bmm(x, y)
        print("torch.bmm example ")
        print("x.shape is ", x.shape)
        print("y.shape is ", y.shape)
        print("z.shape is ", z.shape) ## [64, 1, 3]
    
    如果有一天我们淹没在茫茫人海中庸碌一生,那一定是我们没有努力活得丰盛
  • 相关阅读:
    mui 关闭除指定页面之外的其他所有页面.
    javascript 工厂模式
    DOM事件对象与IE事件对象
    animation属相详解
    webpack概念
    小程序获取form_id 与 小程序获取openid
    小程序分享自定义样式
    node生成图片
    小程序弹出层点透问题
    pm2配置文件介绍
  • 原文地址:https://www.cnblogs.com/yeran/p/11288171.html
Copyright © 2011-2022 走看看