.mm()
Anonymous contributor
Published Oct 17, 2024
Contribute to Docs
In PyTorch, the .mm()
method calculates the matrix product of two given tensors.
Syntax
torch.mm(ten1, ten2, *, out=None)
ten1
: The first tensor to be multiplied.ten2
: The second tensor to be multiplied.out
(Optional): The output tensor to be used. The default value isNone
.
Note: If
ten1
is a(m x n)
tensor andten2
is a(n x p)
tensor, thenout
will be a(m x p)
tensor.
Example
The following example demonstrates the usage of the .mm()
method:
import torch# Define two tensorsten1 = torch.tensor([[1, 2, 3],[4, 3, 8],[1, 7, 2]])ten2 = torch.tensor([[2, 4, 1],[1, 3, 6],[2, 6, 5]])# Multiply the tensorsout = torch.mm(ten1, ten2)print(out)
The above code produces the following output:
tensor([[10, 28, 28],[27, 73, 62],[13, 37, 53]])
Codebyte Example
The following codebyte example shows the use of the .mm()
method:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.