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

Useful Functions On Pytorch Tensor

Some functions which can be quite helpful when working with pytorch tensors.

  • Torch Tensor a multi-dimensional matrix containing elements of a single data type.

Functions are:-

  • torch.unique()
  • torch.matrix_power()
  • torch.mm()
  • torch.unbind()
  • torch.clamp()
# Import torch and other required modules
import torch

Function 0 - torch.tensor

Tensor is a number, vector, matrix or any n-dimensional array. Let's create a tensor with a single number:

# Example 1 - working
torch.tensor(1)
tensor(1)

Function to create a single tensor in pytorch.