Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
Interesting Functions in tensor
An short introduction about PyTorch and about the chosen functions.
- Divide Function
- Cosine Function
- Chunk Function
- HStack Function
- Reshape Function
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
Dividing each elements in x by elements in y
x = torch.tensor([[1., 3, 5],
[2, 4, 6]])
y = torch.full((2, 3), 4.)
torch.div(x, y)
tensor([[0.2500, 0.7500, 1.2500],
[0.5000, 1.0000, 1.5000]])