-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Term Entry] PyTorch Tensor Operations: .permute() (#5886)
* [Term Entry] PyTorch Tensor Operations: .permute() * Update permute.md minor fixes ---------
- Loading branch information
1 parent
91cb389
commit 6afa7a5
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
content/pytorch/concepts/tensor-operations/terms/permute/permute.md
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,55 @@ | ||
--- | ||
Title: '.permute()' | ||
Description: 'Returns a view of the given tensor with its dimensions permuted or rearranged according to a specific order.' | ||
Subjects: | ||
- 'AI' | ||
- 'Data Science' | ||
Tags: | ||
- 'AI' | ||
- 'Data Types' | ||
- 'Deep Learning' | ||
- 'Functions' | ||
CatalogContent: | ||
- 'intro-to-py-torch-and-neural-networks' | ||
- 'paths/data-science' | ||
--- | ||
|
||
In PyTorch, the **`.permute()`** function returns a view of a given [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors) with its dimensions permuted or rearranged according to a specific order. | ||
|
||
## Syntax | ||
|
||
```pseudo | ||
torch.permute(input, dims) | ||
``` | ||
|
||
- `input`: The tensor whose dimensions are to be permuted. | ||
- `dims`: The order in which the dimensions are to be permuted. | ||
|
||
## Example | ||
|
||
The following example demonstrates the usage of the `.permute()` function: | ||
|
||
```py | ||
import torch | ||
|
||
# Create a tensor of size (2, 3, 4) | ||
ten = torch.randn(2, 3, 4) | ||
|
||
# Permute the dimensions of the tensor in the order (2, 0, 1) | ||
res = torch.permute(ten, (2, 0, 1)) | ||
|
||
# Print the size of the resultant tensor | ||
print(res.size()) | ||
``` | ||
|
||
In the above example, the order `(2, 0, 1)`: | ||
|
||
- Moves the dimension located at index `2` to index `0` | ||
- Moves the dimension located at index `0` to index `1` | ||
- Moves the dimension located at index `1` to index `2` | ||
|
||
The above code produces the following output: | ||
|
||
```shell | ||
torch.Size([4, 2, 3]) | ||
``` |