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

Five Basic Pytorch tensor

Subtitle Here

An short introduction about PyTorch and about the chosen functions.

  • torch.clamp
  • torch.histc
  • torch.where
  • torch.Backward
  • torch.mean
# Import torch and other required modules
import torch
import numpy as np

Function 1 - torch.clamp

The function limits the vaules of the elements in the tensor to be between a max and a min thereby defining a range for the tensor to be in

inputs

1.minimium value
2. maximum value

  1. tensor shape.

#outputs
the changed tensor which has values replaced by either min or maximum.


t = torch.tensor([[0, 200, 102, 866, 44, 5, 800, -91], [80, 143, 1200, 666, 424, 52, 1030, 989.]])

As you can see it changed the tensor with the following min and max values