Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
Assignment 1 - 5 interesting functions related to PyTorch tensors
I picked up this choice of 5 functions from the docs because the following functions are a bit awkward as written in the docs and I hope to write a simpler explanation.
Function 1 - torch.gather
Let's define an input 2-dimensional tensor with size 3 per 3
import torch
t = torch.tensor([[1,2,3],[4,5,6],[7,8,9]])
print(t)
tensor([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
Now we define another tensor, so called index
, with the same dimension and size and we put 0,1 and 2 as values, because they are the possible indexes of the input tensor, but we shift them, in order to produce a visible effect