Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
Some of basic PyTorch’s tensor functions
Torch
Following are the functions explained in this notebook
- torch.cat
- torch.reshape
- torch.take
- torch.where
- torch.matmul
# Import torch and other required modules
import torch
Function 1 - torch.cat
Concatenates the given sequence of tensors
# Example 1 - working (change this)
x = torch.randn(2, 4)
torch.cat((x, x, x), 0)
tensor([[ 0.5102, 0.6423, 0.0553, -2.1433],
[ 0.2341, -0.8493, -1.7137, -1.5663],
[ 0.5102, 0.6423, 0.0553, -2.1433],
[ 0.2341, -0.8493, -1.7137, -1.5663],
[ 0.5102, 0.6423, 0.0553, -2.1433],
[ 0.2341, -0.8493, -1.7137, -1.5663]])
Concatenates tensor x 3 times and create new tensor