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

PyTorch Tensors - That's Interesting !

A torch.tensor is a multi-dimensional matrix containing elements of a single data type.
Let's dive deep and understand some interesting functions of PyTorch tensors -

  • randn()
  • imag()
  • hypot()
  • bincount()
  • bucketize()

Before we begin, let's import PyTorch

import torch

Function 1 - torch.randn

  • Returns a tensor filled with random numbers from a normal distribution with mean 0 and variance 1 (also called the standard normal distribution).
  • Parameters:
    • size(int...) --> A sequence of integers defining the shape of tensor.

Let's create a tensor of a single element using randn

x = torch.randn(1)
x
tensor([-0.9204])