Skip to content
This repository was archived by the owner on Feb 27, 2026. It is now read-only.

Commit 858096d

Browse files
Add documentation for .aminmax() method
Fixes #8238
1 parent 87d0ba1 commit 858096d

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

  • content/pytorch/concepts/tensor-operations/terms/aminmax
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
Title: '.aminmax()'
3+
Description: 'Returns both the minimum and maximum values of a tensor along a specified dimension or across the entire tensor.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Data Science'
7+
Tags:
8+
- 'Deep Learning'
9+
- 'Methods'
10+
- 'Programming'
11+
- 'PyTorch'
12+
CatalogContent:
13+
- 'intro-to-py-torch-and-neural-networks'
14+
- 'paths/data-science'
15+
---
16+
17+
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 is more efficient than calling `.amin()` and `.amax()` separately, as it requires only one pass through the data. 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.
18+
19+
## Syntax
20+
21+
```pseudo
22+
torch.aminmax(input)
23+
```
24+
25+
**Parameters:**
26+
27+
- `input`: The input tensor to find the minimum and maximum values from.
28+
**Return value:**
29+
30+
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.
31+
32+
## Example
33+
34+
This example shows how to use the `.aminmax()` method to find the minimum and maximum values of a tensor:
35+
36+
```py
37+
import torch
38+
39+
# Create a sample tensor
40+
tensor = torch.tensor([[3.5, 1.2, 8.7],
41+
[4.1, 9.3, 2.6],
42+
[7.0, 5.4, 6.2]])
43+
44+
# Find minimum and maximum values of the entire tensor
45+
result = torch.aminmax(tensor)
46+
print("Result:", result)
47+
print("Minimum value:", result.min)
48+
print("Maximum value:", result.max)
49+
```
50+
51+
This example results in the following output:
52+
53+
```shell
54+
torch.return_types.aminmax(min=tensor(1.2000),
55+
max=tensor(9.3000)
56+
)
57+
Minimum value: tensor(1.2000)
58+
Maximum value: tensor(9.3000)
59+
```
60+
61+
In this example the maximum value is `9.3000` and the minimum value is `1.2000`.

0 commit comments

Comments
 (0)