From e4d362e199581d89b84ec5b424f39699b567d3cf Mon Sep 17 00:00:00 2001 From: Sriparno Roy Date: Tue, 17 Sep 2024 19:55:57 +0530 Subject: [PATCH 1/3] [Term Entry] PyTorch Tensors: .mm() --- .../pytorch/concepts/tensors/terms/mm/mm.md | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 content/pytorch/concepts/tensors/terms/mm/mm.md diff --git a/content/pytorch/concepts/tensors/terms/mm/mm.md b/content/pytorch/concepts/tensors/terms/mm/mm.md new file mode 100644 index 00000000000..cd2b46471b3 --- /dev/null +++ b/content/pytorch/concepts/tensors/terms/mm/mm.md @@ -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) +``` From 5d101d9cff3ba9a7d89be440c002250fd7e524aa Mon Sep 17 00:00:00 2001 From: Sriparno Roy Date: Wed, 25 Sep 2024 13:23:10 +0530 Subject: [PATCH 2/3] Update path --- .../concepts/{tensors => tensor-operations}/terms/mm/mm.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename content/pytorch/concepts/{tensors => tensor-operations}/terms/mm/mm.md (100%) diff --git a/content/pytorch/concepts/tensors/terms/mm/mm.md b/content/pytorch/concepts/tensor-operations/terms/mm/mm.md similarity index 100% rename from content/pytorch/concepts/tensors/terms/mm/mm.md rename to content/pytorch/concepts/tensor-operations/terms/mm/mm.md From 7ce3efb827d0bdc784d1fd540dd50368c264a7dd Mon Sep 17 00:00:00 2001 From: Sriparno Roy Date: Wed, 9 Oct 2024 15:21:57 +0530 Subject: [PATCH 3/3] Update mm.md --- content/pytorch/concepts/tensor-operations/terms/mm/mm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/mm/mm.md b/content/pytorch/concepts/tensor-operations/terms/mm/mm.md index cd2b46471b3..d29aff253c8 100644 --- a/content/pytorch/concepts/tensor-operations/terms/mm/mm.md +++ b/content/pytorch/concepts/tensor-operations/terms/mm/mm.md @@ -26,7 +26,7 @@ torch.mm(ten1, ten2, *, out=None) - `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. +> **Note:** 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