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

A Mixed Bag of Tensors Operations

Pytorch is machine learning library that is based on torch library, which is used for processing tensors, pytorch is used as it automatically computes the derivate of a variable w.r.t other tensors and it can perform complex caclulations on huge amount of data much more efficienlty by using GPU, this helps training the models faster, other than that PyTorch interoperates well with Numpy to leverage its existing ecosystem of tools and libraries.

  • TORCH.MUL :- It takes a tensor and a scalar as an input and multiplies them together to return a new tensor.
  • TORCH.WHERE :- It takes two tensors as inputs and return a new tensor based on the condition specified.
  • TORCH.T :- It swapes the dimensions of the input tensor and returns a new tansposed tensor.
  • TORCH.POW :- It takes a tesnor as an input, raises it to the power of the exponent given to it and returns the result.
  • TORCH.ADD :- It adds a scalar to every element of the input tensor and returns a new tensor.
import torch

Function 1 - TORCH.MUL

The function torch.mul takes two a inputs, 1) a input tensor, 2) a scalar, multiplies each element of the input tensor with the scalar and then returns a new tensor.

Example 1

a=torch.tensor([1,5,9,7])
a
tensor([1, 5, 9, 7])