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

5 Useful PyTorch functions

PyTorch is an open source deep learning framework built to be flexible and modular for research, with the stability and support needed for production deployment. PyTorch provides a Python package for high-level features like tensor computation (like NumPy) with strong GPU acceleration and TorchScript for an easy transition between eager mode and graph mode. With the latest release of PyTorch, the framework provides graph-based execution, distributed training, mobile deployment, and quantization.Here are some functions in

  • torch.arange()
  • torch.chunk()
  • torch.inverse()
  • torch.rand()
  • torch.transpose()
# Import torch and other required modules
import torch

Function 1 - torch.arange()

This function is used to create a tensor that has integers from a specified range.We can use this function to generate a tensor with specific size that contains numbers with the same step value.

torch.arange(9)
tensor([0, 1, 2, 3, 4, 5, 6, 7, 8])

In this example,the function create a one dimension tensor with five elements.