-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Added .aminmax() method documentation #8247
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
Open
abdultalha0862
wants to merge
3
commits into
Codecademy:main
Choose a base branch
from
abdultalha0862:add-aminmax-function
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
74 changes: 74 additions & 0 deletions
74
content/pytorch/concepts/tensor-operations/terms/aminmax/aminmax.md
This file contains hidden or 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,74 @@ | ||
| --- | ||
| Title: '.aminmax()' | ||
| Description: 'Returns both the minimum and maximum values of a tensor along a specified dimension or across the entire tensor.' | ||
| Subjects: | ||
| - 'Computer Science' | ||
| - 'Data Science' | ||
| Tags: | ||
| - 'Deep Learning' | ||
| - 'Methods' | ||
| - 'Programming' | ||
| - 'PyTorch' | ||
| CatalogContent: | ||
| - 'intro-to-py-torch-and-neural-networks' | ||
| - 'paths/data-science' | ||
| --- | ||
|
|
||
| The **`.aminmax()`** method in PyTorch computes both the minimum and maximum values of a [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors) in a single operation. This method performs both reductions in a single pass through the data, making it more efficient than calling `.amin()` and `.amax()` separately. It can operate on the entire tensor or along a specific dimension, making it useful for data analysis, normalization, and monitoring value ranges in neural networks. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```pseudo | ||
| torch.aminmax(input, dim=None, keepdim=False, *, out=None) | ||
| ``` | ||
|
|
||
| **Parameters:** | ||
|
|
||
| - `input` (Tensor): The input tensor to find the minimum and maximum values from. | ||
| - `dim` (int or tuple of ints, optional): The dimension(s) along which to compute the values. If `None`, computes over the entire tensor. | ||
| - `keepdim` (bool, optional): If `True`, retains reduced dimensions with size 1. Default is `False`. | ||
| - `out` (tuple of Tensors, optional): A tuple of two tensors to store the output. | ||
|
|
||
| **Return value:** | ||
|
|
||
| The `.aminmax()` method returns a named tuple `(min, max)` containing two tensors: the minimum values in the `min` field and the maximum values in the `max` field. | ||
|
|
||
| ## Example | ||
|
|
||
| This example shows how to use the `.aminmax()` method to find the minimum and maximum values of a tensor: | ||
|
|
||
| ```py | ||
| import torch | ||
|
|
||
| # Create a sample tensor | ||
| tensor = torch.tensor([[3.5, 1.2, 8.7], | ||
| [4.1, 9.3, 2.6], | ||
| [7.0, 5.4, 6.2]]) | ||
|
|
||
| # Find minimum and maximum values of the entire tensor | ||
| result = torch.aminmax(tensor) | ||
|
|
||
| print("Minimum value:", result.min) | ||
| print("Maximum value:", result.max) | ||
|
|
||
| # Find minimum and maximum values along dimension 0 | ||
| result_dim = torch.aminmax(tensor, dim=0) | ||
|
|
||
| print("\nMinimum values along dim 0:", result_dim.min) | ||
| print("Maximum values along dim 0:", result_dim.max) | ||
| ``` | ||
|
|
||
| This example results in the following output: | ||
|
|
||
| ```shell | ||
| Minimum value: tensor(1.2000) | ||
| Maximum value: tensor(9.3000) | ||
|
|
||
| Minimum values along dim 0: tensor([3.5000, 1.2000, 2.6000]) | ||
| Maximum values along dim 0: tensor([7.0000, 9.3000, 8.7000]) | ||
| ``` | ||
|
|
||
| In this example: | ||
|
|
||
| - **Entire tensor**: Returns single min (1.2000) and max (9.3000) values across all elements. | ||
| - **Along dimension 0**: Returns min and max for each column, producing tensors with 3 values each. | ||
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.
Uh oh!
There was an error while loading. Please reload this page.