Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
How to Perform Basic Matrix Operations with Pytorch Tensor
In this Notebook, I try to Explain Basic Matrix Operations using PyTorch tensor.
Lets Discuss Tensor First!
Tensor is a multi-dimensional matrix containing elements of a single data type.
like tensor is multidimensional so you can Easily handle number Which is a zero-dimensional matrix, vector Which is a single-dimensional matrix, matrix Which is a two-dimensional matrix, or multi-dimensions matrix.
# Import torch and other required modules
import torch
# Number
t1 = torch.tensor(9.)
t1
tensor(9.)
# vector
t2 = torch.tensor([1,2,3,4,5])
t2
tensor([1, 2, 3, 4, 5])
# matrix
t3 = torch.tensor([[2., 6],
[8, 9],
[9, 4]])
t3
tensor([[2., 6.],
[8., 9.],
[9., 4.]])