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

Getting familiar with 5 interesting PyTorch functions.

This is a brief description of functions that I found interesting using PyTorch tensors.

The chosen functions are:

  • torch.as_strided
  • torch.trace
  • torch.rot90
  • torch.repeat_interleave
  • torch.median
# Import torch and other required modules
import torch

Function 1 - torch.as_strided

Create a view of an existing torch.Tensor input with specified size, stride and storage_offset.

# First we create a tensor
t = torch.randint(1,10, (3,3))
t
tensor([[2, 9, 9],
        [3, 1, 2],
        [4, 5, 3]])

We create a 3x3 tensor with values from 1 to 10.