pytorch中的@的作用

在PyTorch中,@符号用作矩阵乘法的运算符,这与Python 3.5及以上版本引入的矩阵乘法运算符一致。@效果等同于使用torch.matmul()或torch.mm()函数(后者仅适用于二维张量)。

相乘的两个矩阵必须满足:矩阵A的列数必须与矩阵B的行数相匹配。

假设有两个张量A和B,你想计算它们的矩阵乘积,

import torch


A = torch.tensor([[1, 2],
                  [3, 4]])

B = torch.tensor([[2, 0],
                  [0, 2]])

C = A @ B

print(C)

"""
tensor([[2, 4],
        [6, 8]])
"""

相关推荐

  1. pytorch@作用

    2024-04-23 13:08:03       19 阅读
  2. PyTorchself.layers作用

    2024-04-23 13:08:03       30 阅读
  3. PyTorchitem()函数作用(python)

    2024-04-23 13:08:03       13 阅读
  4. js()作用

    2024-04-23 13:08:03       36 阅读
  5. pytorchgather函数定义和作用是什么?

    2024-04-23 13:08:03       21 阅读
  6. Pytorch当中nn.Identity()层作用

    2024-04-23 13:08:03       30 阅读
  7. pytorch对象或变量后面加上.cuda()函数作用

    2024-04-23 13:08:03       18 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-23 13:08:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-23 13:08:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-23 13:08:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-23 13:08:03       20 阅读

热门阅读

  1. 开发语言漫谈-Vue

    2024-04-23 13:08:03       12 阅读
  2. 【Linux】驱动_1_hello驱动

    2024-04-23 13:08:03       13 阅读
  3. FineReport报表问题- SET LOGSIZE FAILED 解决

    2024-04-23 13:08:03       14 阅读
  4. 通讯协议---USB枚举过程

    2024-04-23 13:08:03       11 阅读
  5. 页面跳转的几种方式

    2024-04-23 13:08:03       16 阅读
  6. 主流微前端框架对比与选择策略

    2024-04-23 13:08:03       17 阅读
  7. Stable Diffusion Web UI Windows部署及坑

    2024-04-23 13:08:03       13 阅读