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

Some useful tensor functions

PyTorch is a Python-based scientific computing package that uses the power of graphics processing units. It is also one of the preferred deep learning research platforms built to provide maximum flexibility and speed. My picks for the tensor functions are;

  • stack
  • det
  • mean
  • masked_select
  • inverse
import torch
#importing required package.
Function 1: Stack

stack concatenates a sequence of tensors along a new dimension while 'cat' concatenates along the existing dimension.

t1=torch.tensor([1.,2,3,4])
t2=torch.tensor([10.,11,12,13])
t3=torch.tensor([5.,6,7])
torch.stack((t1,t2),dim=1)
tensor([[ 1., 10.],
        [ 2., 11.],
        [ 3., 12.],
        [ 4., 13.]])