Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Term Entry] PyTorch Tensor Operations: .mm() #5328

Merged
merged 19 commits into from
Oct 17, 2024
Merged
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions content/pytorch/concepts/tensor-operations/terms/mm/mm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
Title: '.mm()'
Description: 'Calculates the matrix product of two given tensors.'
Subjects:
- 'AI'
- 'Data Science'
Tags:
- 'AI'
- 'Arrays'
- 'Data Structures'
- 'Deep Learning'
CatalogContent:
- 'intro-to-py-torch-and-neural-networks'
- 'paths/computer-science'
---

In PyTorch, the **`.mm()`** method calculates the matrix product of two given tensors.

## Syntax

```pseudo
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 is `None`.

If `ten1` is a `(m x n)` tensor and `ten2` is a `(n x p)` tensor, then `out` will be a `(m x p)` tensor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mentioned this as a note


## Example

The following example demonstrates the usage of the `.mm()` method:

```py
import torch

# Define two tensors
ten1 = 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 tensors
out = torch.mm(ten1, ten2)

print(out)
```

The above code produces the following output:

```shell
tensor([[10, 28, 28],
[27, 73, 62],
[13, 37, 53]])
```

## Codebyte Example

The following codebyte example shows the use of the `.mm()` method:

```codebyte/python
import torch

# Define two tensors
ten1 = torch.tensor([[6, 8, 1],
[5, 2, 4],
[9, 3, 7]])

ten2 = torch.tensor([[9, 2, 3],
[7, 8, 4],
[6, 1, 5]])

# Multiply the tensors
out = torch.mm(ten1, ten2)

print(out)
```
Loading