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

Assignment -1

Five basic function of torch.tensor

An short introduction about PyTorch and about the chosen functions.

  • new_full & new_empty
  • flatten
  • arrange
  • randn
  • sigmoid
# Import torch and other required modules
import torch

Function 1 - torch.new_full & new_empty

As the name signifies, new_full is used to create a tensor with a defined size and some fill_value in it. Similiarly new_empty is used to create an empty tensor of the defined size.
Both create a return a new tensor. They both do not effect the tensor it is called from.

# Example 1 - working (change this)
tensor1 = torch.zeros((2,3), dtype=torch.float64)
tensor2 = tensor1.new_full((3,4), 90. , dtype=torch.int8)

new_empty fills the tensor with unitialized data of the mentioned size.