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

Assignment 1

Tensor Operations Pytorch

  • add
  • zeros
  • rand
  • is_tensor
  • view
# Import torch and other required modules
import torch

Function 1 - add

This function Adds 2 tensors

# Example 1 - working 
x = torch.tensor([[1, 2], [3, 4]])
y = torch.tensor([[6,8],[5,2]])
z = torch.add(x,y)
z
tensor([[ 7, 10],
        [ 8,  6]])

In this eg: I am adding 2 2-D tensors