Positron: Linear Algebra Library For Python

A new library for Python/Numpy.

Photo by Greg Rosenke on Unsplash

Introduction

In this article, I will introduce the current state of a newly developed (and still in progress) Linear Algebra library for Python, called Positron. This is not a replica of Numpy, it is instead an extension for numpy.

The main focus of Positron is to implement functions that are common (or rare) in Linear Algebra but are not in Numpy by default.

All the code for this project is on the web, namely on GitHub. Contributions and suggestions are really well welcomed!

Concepts

Linear Algebra is a mathematical discipline that deals with vectors and matrices and, more generally, with vector spaces and linear transformations.

Python is one of the most popular programing language to use for Data Science, Machine Learning, and Artificial Intelligence among others. Deep Learning -a subset of Artificial Intelligence- relies heavily on Linear Algebra.

Numpy is the most used Linear Algebra library for Python. It is fast, pretty well documented, widely used and kind of easy to work with.

Goals Of Positron

  • Implement functions from Linear Algebra.
  • Only implement what is not in Numpy by default.
  • The functions should be as fast as possible.
  • Make the library well useable for everyone.
Photo by Saad Ahmad on Unsplash

Implemented Functions

Here you can find some of the currently implemented functions. Most of them are using the numpy.ndarray class from the numpy library for storing matrices.

Matrix Chess Table Rule

Applies the Chess Table Rule to the given matrix. Note that the matrix has to be a square matrix and at least 2 rows tall.

Chess Table Rule function

It creates a new matrix by multiplying specific elements by -1. If we count indices from one:

  • For every odd row: Every even indexed element multiplies by -1.
  • For every even row: Every odd element multiplies by -1.

Matrix Adjungate

Creates an adjungate matrix from the given one. Note that the matrix has to be a square matrix.

Adjugate function

Matrix Subdeterminants

Returns the subdeterminants of the given matrix. Note that the matrix has to be a square matrix and at least 3 rows tall.

Subdeterminant function

Matrix Determinant

Using the Subdeterminant extractor function, we can create a general determinant calculator function shown here.

Determinant function

This function will return the determinant of the given matrix. Note that the matrix has to be a square matrix and at least 2 rows tall.

Matrix Inverse

This might be the most interesting function of all. The matrix inverse. This function calculates the given matrix’s inverse.

Inverse and Matrix Singularity checker function

An inverse can be helpful in solving equations like: Ax=b, where the question is x=?. The solution for this equation is given with a matrix inverse:

Where I is an identity matrix.

Future Functions: Eigenvalues and Eigenvectors

This is an idea for not yet implemented function(s).

There are some methods for finding matrix eigenvalues and eigenvectors, so there must be a way to generalize the algorithm and implement it into Positron.

Photo by Shahadat Rahman on Unsplash

Conclusion

I hope that in this article, I gave you a good enough introduction for the current state (2022. June 7.) of Positron. Remember that It is a free to use library (MIT License) and we, the developers would be really happy to see you contributing to Positron!

Author: Martin Kondor

Sources

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store