From 446b5ebbff7146ec00b45994b2bbf5ff88f8fac3 Mon Sep 17 00:00:00 2001 From: Neema Date: Mon, 2 Dec 2024 12:13:06 +0530 Subject: [PATCH 1/7] Added file on movedim --- .../pytorch/concepts/tensor-operations/terms/movedim/movedim.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md diff --git a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md new file mode 100644 index 00000000000..e69de29bb2d From 66e49eb1ec2987cc0625ce9ec29da0173c82ed01 Mon Sep 17 00:00:00 2001 From: Neema Date: Mon, 2 Dec 2024 12:18:37 +0530 Subject: [PATCH 2/7] The correct file --- .../terms/movedim/movedim.md | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md index e69de29bb2d..4f0e727308d 100644 --- a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md +++ b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md @@ -0,0 +1,129 @@ +--- +Title: '.movedim()' +Description: 'A function used to reorder the dimensions of a tensor.' +Subjects: + - 'AI' + - 'Data Science' +Tags: + - 'AI' + - 'Arrays' + - 'Data Structures' + - 'Deep Learning' +CatalogContent: + - 'intro-to-py-torch-and-neural-networks' + - 'paths/computer-science' +--- + +**`movedim()`** is used to move specific dimension of the input to a specified position. The other dimensions that are not explicitly mentioned remain in the original order. + +## Syntax + +```pseudo +torch.movedim(input, source, destination) +``` + +- `input`: The input tensor. +- `source`: Original position of the dimensions that need to move. It must be unique +- `destination`: Destination position for each of the original dimension. It must be unique + +## Example + +The following example demonstrates the use of `.movedim()`: + +```py +import torch + +# Define a 1D tensor +a = torch.tensor([[1, 2, 3, -8]]) + +# Define a 2D tensor +b = torch.tensor([[1, 2, 3, -8], + [4, 3, 8, 0], + [-1, 7, 6, 3], + [5, 6, 9, 0]]) + +# Define a 3D tensor +c = torch.randn(2, 2, 3) + +# Define a 4D tensor +d = torch.randn(2, 3, 2, 3) + +# Move dimension 0 to dimension 1 for 1D tensor +a1 = torch.movedim(a, 0, 1) +print("One Dimensional tensor:") +print(a1) +print("\n") + +# Move dimension 0 to dimension 1 for 2D tensor +b1 = torch.movedim(b, 0, 1) +print("Two Dimensional tensor:") +print(b1) +print("\n") + +# Move dimension 0 to dimension 1 for 3D tensor +c1 = torch.movedim(c, 0, 1) +print("Three Dimensional tensor (Dim 1):") +print(c1) +print("\n") + +# Move dimension 0 to dimension 2 for 3D tensor +c2 = torch.movedim(c, 0, 2) +print("Three Dimensional tensor (Dim 2):") +print(c2) +print("\n") + +# Move dimensions [0, 1] to positions [2, 3] +d1 = torch.movedim(d, [0, 1], [2, 3]) +print("Four Dimensional tensor:") +print(d1) +``` + +```shell +One Dimensional tensor: +tensor([[ 1], + [ 2], + [ 3], + [-8]]) + +Two Dimensional tensor: +tensor([[ 1, 4, -1, 5], + [ 2, 3, 7, 6], + [ 3, 8, 6, 9], + [-8, 0, 3, 0]]) + +Three Dimensional tensor (Dim 1): +tensor([[[ 1.0064, -1.2284, -1.1452], + [-0.9374, 1.2943, -1.7862]], + + [[ 0.4316, 3.1050, -0.4264], + [-0.9219, 1.6863, -0.3411]]]) + +Three Dimensional tensor (Dim 2): +tensor([[[ 1.0064, -0.9374], + [-1.2284, 1.2943], + [-1.1452, -1.7862]], + + [[ 0.4316, -0.9219], + [ 3.1050, 1.6863], + [-0.4264, -0.3411]]]) + +Four Dimensional tensor: +tensor([[[[ 0.0753, 1.5373, 0.0765], + [-3.1675, 0.2926, 0.5799]], + + [[-0.1520, -0.4855, 1.9026], + [-1.6107, 0.5367, -0.3401]], + + [[-0.9148, -0.6213, 0.5939], + [-0.6407, -1.0397, -0.7044]]], + + + [[[ 0.3897, 0.6399, 1.0818], + [ 0.7111, -1.3950, -1.3415]], + + [[-0.3749, 2.3008, -0.2464], + [ 1.4121, -0.3554, -0.5184]], + + [[-0.3224, -0.9296, 0.1633], + [-0.2641, 0.8230, 0.1766]]]]) +``` \ No newline at end of file From b03d58f9283ab02b90680cf39a61474ce45a8f54 Mon Sep 17 00:00:00 2001 From: Neema Date: Mon, 2 Dec 2024 12:22:46 +0530 Subject: [PATCH 3/7] some basic edits --- .../concepts/tensor-operations/terms/movedim/movedim.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md index 4f0e727308d..cab7dd861dc 100644 --- a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md +++ b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md @@ -14,7 +14,7 @@ CatalogContent: - 'paths/computer-science' --- -**`movedim()`** is used to move specific dimension of the input to a specified position. The other dimensions that are not explicitly mentioned remain in the original order. +**`.movedim()`** is used to move specific dimension of the input to a specified position. The other dimensions that are not explicitly mentioned remain in the original order. ## Syntax @@ -23,8 +23,8 @@ torch.movedim(input, source, destination) ``` - `input`: The input tensor. -- `source`: Original position of the dimensions that need to move. It must be unique -- `destination`: Destination position for each of the original dimension. It must be unique +- `source`: Original position of the dimensions that need to move. It must be unique. +- `destination`: Destination position for each of the original dimension. It must be unique. ## Example From 3bc972d7266f0b1bbce23fba9a10ca5a69e3a053 Mon Sep 17 00:00:00 2001 From: Neema Date: Wed, 4 Dec 2024 14:06:52 +0530 Subject: [PATCH 4/7] Added edits --- .../tensor-operations/terms/movedim/movedim.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md index cab7dd861dc..ba945875d3b 100644 --- a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md +++ b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md @@ -1,6 +1,6 @@ --- Title: '.movedim()' -Description: 'A function used to reorder the dimensions of a tensor.' +Description: 'Returns a tensor with the dimensions moved from the positions specified in source to the positions specified in destination.' Subjects: - 'AI' - 'Data Science' @@ -14,7 +14,7 @@ CatalogContent: - 'paths/computer-science' --- -**`.movedim()`** is used to move specific dimension of the input to a specified position. The other dimensions that are not explicitly mentioned remain in the original order. +In Pytorch, **`.movedim()`** is used to move specific dimensions of the input tensor to a specified positions, while the other dimensions that are not explicitly mentioned remain in their original order. ## Syntax @@ -22,9 +22,9 @@ CatalogContent: torch.movedim(input, source, destination) ``` -- `input`: The input tensor. -- `source`: Original position of the dimensions that need to move. It must be unique. -- `destination`: Destination position for each of the original dimension. It must be unique. +- `input`: The input tensor whose dimensions are to be rearranged. +- `source`: The dimensions to be moved. Can be a single integer or a tuple of integers. +- `destination`: The target positions for the dimensions specified in `source`. It should have the same length as `source`. ## Example @@ -72,7 +72,7 @@ print("Three Dimensional tensor (Dim 2):") print(c2) print("\n") -# Move dimensions [0, 1] to positions [2, 3] +# Move dimensions [0, 1] to positions [2, 3] for 4D tensor d1 = torch.movedim(d, [0, 1], [2, 3]) print("Four Dimensional tensor:") print(d1) From 933a8cd206482ff2ab5ada92271a1d9a490b09a5 Mon Sep 17 00:00:00 2001 From: Radhika-okhade Date: Thu, 19 Dec 2024 23:56:47 +0530 Subject: [PATCH 5/7] Update content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md --- .../pytorch/concepts/tensor-operations/terms/movedim/movedim.md | 1 + 1 file changed, 1 insertion(+) diff --git a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md index ba945875d3b..c961df30a4c 100644 --- a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md +++ b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md @@ -77,6 +77,7 @@ d1 = torch.movedim(d, [0, 1], [2, 3]) print("Four Dimensional tensor:") print(d1) ``` +This example will generate the following output: ```shell One Dimensional tensor: From 071bd7f8cf6bc37744d31a9c89941ab4097d2b0c Mon Sep 17 00:00:00 2001 From: Radhika-okhade Date: Thu, 19 Dec 2024 23:57:19 +0530 Subject: [PATCH 6/7] Update content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md --- .../pytorch/concepts/tensor-operations/terms/movedim/movedim.md | 1 + 1 file changed, 1 insertion(+) diff --git a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md index c961df30a4c..a6633334a5a 100644 --- a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md +++ b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md @@ -77,6 +77,7 @@ d1 = torch.movedim(d, [0, 1], [2, 3]) print("Four Dimensional tensor:") print(d1) ``` + This example will generate the following output: ```shell From d6f4d312bf8ce72c3799593edfec7fbf99a04408 Mon Sep 17 00:00:00 2001 From: Radhika-okhade Date: Fri, 20 Dec 2024 00:01:26 +0530 Subject: [PATCH 7/7] Update movedim.md Fixed formating issue --- .../pytorch/concepts/tensor-operations/terms/movedim/movedim.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md index a6633334a5a..33689588f81 100644 --- a/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md +++ b/content/pytorch/concepts/tensor-operations/terms/movedim/movedim.md @@ -128,4 +128,4 @@ tensor([[[[ 0.0753, 1.5373, 0.0765], [[-0.3224, -0.9296, 0.1633], [-0.2641, 0.8230, 0.1766]]]]) -``` \ No newline at end of file +```