-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e4d362e
[Term Entry] PyTorch Tensors: .mm()
Sriparno08 f448e63
Merge branch 'main' of https://github.com/Codecademy/docs into pytorc…
Sriparno08 5d101d9
Update path
Sriparno08 b378249
Merge branch 'main' into pytorch-mm
Sriparno08 45c1896
Merge branch 'main' of https://github.com/Codecademy/docs into pytorc…
Sriparno08 aa572ba
Merge branch 'main' into pytorch-mm
Sriparno08 bbf443d
Merge branch 'main' into pytorch-mm
Sriparno08 be3c58e
Merge branch 'main' into pytorch-mm
Sriparno08 1bd762f
Merge branch 'main' into pytorch-mm
Sriparno08 af0c502
Merge branch 'main' of https://github.com/Codecademy/docs into pytorc…
Sriparno08 972c893
Merge branch 'main' into pytorch-mm
Sriparno08 90eec35
Merge branch 'main' into pytorch-mm
cigar-galaxy82 b755522
Merge branch 'pytorch-mm' of https://github.com/Sriparno08/Codecademy…
Sriparno08 7ce3efb
Update mm.md
Sriparno08 7620e51
Merge branch 'main' into pytorch-mm
Sriparno08 cdfe596
Merge branch 'main' into pytorch-mm
Sriparno08 ade72a8
Merge branch 'main' into pytorch-mm
Sriparno08 b1b60f2
Merge branch 'main' into pytorch-mm
Sriparno08 f262ac3
Merge branch 'main' into pytorch-mm
cigar-galaxy82 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
## 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) | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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