Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
Functions from PyTorch Library
An short introduction about PyTorch and about the chosen functions.
- torch.argmax()
- torch.argmin()
- torch.mean()
- torch.median()
- torch.unique()
Before we begin, let's install and import PyTorch
# Uncomment and run the appropriate command for your operating system, if required
# Linux / Binder
# !pip install numpy torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
# Windows
# !pip install numpy torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
# MacOS
# !pip install numpy torch torchvision torchaudio
# Import torch and other required modules
import torch
Function 1 - torch.argmax()
Returns the indices of the maximum value of all elements in the input tensor.
a=torch.randn(4, 4)
a
tensor([[-1.4222, -0.4501, 2.1666, -0.2640],
[ 0.9964, 0.8415, -0.4781, 0.8133],
[-0.9866, -0.6095, 1.6877, 1.0005],
[-0.9803, 1.7632, 0.2358, -0.8230]])