pytorch中的math operation: torch.bmm()

torch.bmm(batch1batch2out=None) → Tensor

Performs a batch matrix-matrix product of matrices stored in batch1 and batch2.

batch1 and batch2 must be 3-D tensors each containing the same number of matrices.

If batch1 is a (b×n×m)tensor, batch2 is a (b×m×p) tensor, out will be a (b×n×p)tensor.

outi=batch1i@batch2outi=batch1i@batch2i

Note

This function does not broadcast. For broadcasting matrix products, see torch.matmul().

Parameters:
  • batch1 (Tensor) – the first batch of matrices to be multiplied
  • batch2 (Tensor) – the second batch of matrices to be multiplied
  • out (Tensoroptional) – the output tensor

Example:

>>> batch1 = torch.randn(10, 3, 4) >>> batch2 = torch.randn(10, 4, 5) >>> res = torch.bmm(batch1, batch2) >>> res.size() torch.Size([10, 3, 5])
    原文作者:pytorch
    原文地址: https://www.cnblogs.com/qinduanyinghua/p/9715163.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞