Operations on Matrices
Five PyTorch's functions for Matrices calculus
PyTorch is an open source machine learning library based on the Torch library, used for applications such as computer vision and natural language processing, primarily developed by Facebook's AI Research lab (FAIR).
A number of pieces of Deep Learning software are built on top of PyTorch, including Uber's Pyro, HuggingFace's Transformers, and Catalyst.
PyTorch provides two high-level features:
Tensor computing (like NumPy) with strong acceleration via graphics processing units (GPU).
Deep neural networks built on a tape-based automatic differentiation system.
In this Post we will be exploring five PyTorch's functions in manipulating matrices computing.
List of functions :
- torch.det
- torch.inverse
- torch.matrix_power
- torch.matrix_rank
- torch.eig
# Import torch and other required modules
import torch
Function 1 - torch.det
torch.det(input) → Tensor
This function is dedicated to calculate the determinant of a matrix.
# Example 1 - working
A = torch.rand(4,4)
A, torch.det(A)
(tensor([[0.9342, 0.1375, 0.1542, 0.9285],
[0.2170, 0.9392, 0.6326, 0.5411],
[0.8192, 0.6394, 0.8450, 0.6089],
[0.3742, 0.2988, 0.9135, 0.7255]]), tensor(0.3124))
This example above illustrate the computing of the determinant of a square matrix 4x4