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

Assignment # 1

About torch.Tensor

PyTorch is a open source machine learning library which can be utilized for Computer vision & natural language processing. Here in this course we will utilize this library extensively as we learn computer vision technology at a length.

Below are some basic function which are being utilized for tensor generation.

  • torch.zeros
  • torch.dtype
  • torch.tensor.item()
  • torch.abs
  • torch.add
# Import torch and other required modules
import torch

Function 1 - torch.zeros

This function is utilized to make a tensor with all Zero elements in it.

# Example 1 - Here we will create the tensor of 5 X 4 having all zero elements in it.
torch.zeros([5,4])
tensor([[0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.]])

By this function, we can create the tensor array with all zero values to generate the matrix. Similar way we can generate 3D matrix as well. Now, let's try this example as well.