Learn practical skills, build real-world projects, and advance your career

Assignment 1

To be submitted before 30 May 2020.

An short introduction about PyTorch and about the chosen functions.

  • torch.index_select()
  • torch.eq()
  • torch.dot()
  • torch.fmod()
  • torch.inverse()
# Import torch and other required modules
import torch

Function 1 - torch.index_select()

torch.index_select(input, dim, index, out=None) --> Tensor

index_select is a function that returns a new tensor which has the entries specified in index of the tensor defined in input.

It has the same number of dimension as the original tensor (defined in input).

# Example 1
#create x using randn with 5 rows and 4 columns
x = torch.randn(5, 4)
x
tensor([[ 0.7081, -0.1952,  0.1616, -0.6794],
        [ 0.2017, -2.0601,  0.4825,  0.0657],
        [ 1.2947,  0.5529, -0.4297, -0.1562],
        [-0.6232,  1.1203, -0.7710,  0.1843],
        [-0.3766,  0.0581, -1.6676, -0.6237]])
#choose the entries you'd like to see in the new tensor
index = torch.tensor([0,2])
index
tensor([0, 2])