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

PyTorch Function

An short introduction about PyTorch and about the chosen functions.

  • torch.is_tensor(obj)
  • torch.set_default_dtype(d)
  • the eye function
  • Arrange function
  • split function
# Import torch and other required modules
import torch
import numpy as np

Function 1 - torch.is_tensor(obj)

This function is to evaluate that the the obj is "tensor" or not, return True when the obj is tensor or False when the obj is not tensor. As in our deep learning we perform our computation and arithimatic operation on tensor, we need to identify them.

# Example 1 - working (change this)
a = torch.tensor([
                  [10,20,30],
                  [40,50,60],
                  [70,80,90]
                  ])
b = np.array([
              [10,20,30],
              [40,50,60],
              [70,80,90]
              ])
print("a is tensor: {}".format(torch.is_tensor(a)))
print("b is tensor: {}".format(torch.is_tensor(b)))
a is tensor: True b is tensor: False

As we can see the 'a' obj return true as it is tensor, and 'b' obj returns False