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

Beginner PyTorch Tensor functions

An short introduction about PyTorch and about the chosen functions.

  • TORCH.NUMEL
  • TORCH.FROM_NUMPY
  • TORCH.ARANGE
  • TORCH.RANDN
  • TORCH.FULL

Before we begin, let's install and import PyTorch

# Uncomment and run the appropriate command for your operating system, if required

# Linux / Binder
# !pip install numpy torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

# Windows
# !pip install numpy torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

# MacOS
# !pip install numpy torch torchvision torchaudio
# Import torch and other required modules
import torch
jovian.commit(project='Tensor-Operations')
[jovian] Detected Colab notebook... [jovian] Please enter your API key ( from https://jovian.ai/ ): API KEY: ·········· [jovian] Uploading colab notebook to Jovian... [jovian] Capturing environment.. [jovian] Committed successfully! https://jovian.ai/ithackermike/tensor-operations

Function 1 - TORCH.NUMEL

The torch.numel function returns the number of elements in a tensor.