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

Assignment 1- All About torch.Tensor

PyTorch

PyTorch is a library for processing tensors.

  • torch.div()
  • torch.remainder()
  • torch.trunc()
  • torch.var_mean()
  • torch.flatten()
# Import torch and other required modules
import torch

Function 1 - torch.div(input, other, out=None)

The function divides each element of the input with the scalar other and returns a new resulting tensor.Parameters: input (Tensor) – the input tensor, other (Number) – the number to be divided to each element of input, out (Tensor, optional) – the output tensor.

# Example 1 - working 
x = torch.tensor([[7.1, 4], [1, 5]])
x
tensor([[7.1000, 4.0000],
        [1.0000, 5.0000]])

In Example 1 the variable x is assigned to tensor.