torch.max(input, dim)
pred = torch.max(input, dim)
Returns the maximum value per row (dim = 1) or column (dim = 0).
_, pred = torch.max(input, dim)
Only the position of the maximum value in each row (dim = 1) or column (dim = 0) is returned.
Example:
import torch
# Construct a 5x3 randomly initialized matrix
x = torch.rand(5, 3)
print('input: ', x)
print('-'*10)
y1 = torch.max(x, 1)
print('max by row: ', y1)
print('-'*10)
y2 = torch.max(x, 0)
print('max by col: ', y2)
print('-'*10)
_, y3 = torch.max(x, 1)
print('max index by row: ', y3)
print('-'*10)
_, y4 = torch.max(x, 0)
print('max index by col: ', y4)
Output result:
input: tensor([[0.5504, 0.3160, 0.2448],
[0.8694, 0.3295, 0.2085],
[0.5530, 0.9984, 0.3531],
[0.2874, 0.1025, 0.9419],
[0.0867, 0.4234, 0.8334]])
----------
max by row: torch.return_types.max(
values=tensor([0.5504, 0.8694, 0.9984, 0.9419, 0.8334]),
indices=tensor([0, 0, 1, 2, 2]))
----------
max by col: torch.return_types.max(
values=tensor([0.8694, 0.9984, 0.9419]),
indices=tensor([1, 2, 3]))
----------
max index by row: tensor([0, 0, 1, 2, 2])
----------
max index by col: tensor([1, 2, 3])
Read More:
- How to Use Printf in HAL Library
- Electron: How to Use BrowserWindow to Create a Window
- Jquery use queue to implement Ajax request queue Simple Example
- Python: How to Create List by Comprehension (Example Codes)
- Android: How to Add Background Music for Activity with Service
- Canvas: How to Implement Video Screenshot Function
- Docker: How to build a rabbitmq image cluster
- Windows Core Audio APIs: How to Progress Loopback Recording and Generate WAV File
- Android: How to get the size of font you set (Example Code)
- C#: How to Get details of the directory where the currently running program is located
- MySQL Batch Add Data and Store Example
- Flutter & Dart Enumeration Example
- Flutter & Dart every() Method Example
- Flutter & Dart Regular Expression Examples
- Opentelemetry + Jaeger Python Version Cross Service Call Example
- Base64 Image Compression Example
- MultipartFile Upload an Image Example
- Open CASCADE Technology 7.7.0 released
- Hutool Excel Import & Export Example
- WCNSS_qcom_cfg.ini WIFI Configuration File Guide