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

Assignment-1

PyTorch basic functions

An short introduction about PyTorch and about the chosen functions.

  • function 1 : torch.unbind(tensor) - splits a tensor into individual elements.
  • function 2 : torch.clamp(input, min, max, out=None) - Clamp all elements in inout tensor between a min and maximum value.
  • function 3 : torch.equal(input, other) - Checks if two tensors are equal.
  • function 4 : torch.median() - Returns the median of elements in a tensor.
  • function 5 : torch.max() - Returns the maximum element value in the tensor.
# Import torch and other required modules
import torch

Function 1 - torch.unbind(tensor)

torch.unbind() splits a tensor into individual elements.

# Example 1 - working (change this)
a = torch.tensor([[15, 22, 43],
                  [54, 45, 62], 
                  [23, 24, 25]])
torch.unbind(a,dim=-1)
(tensor([15, 54, 23]), tensor([22, 45, 24]), tensor([43, 62, 25]))

Function-1 Example-1: Splits tensor a such that each column becomes one tensor