Skip to content

Python for Linear Algebra

These pages provide a showcase of how to use Python to do computations from linear algebra. We will demonstrate both the NumPy (SciPy) and SymPy packages. This is meant to be a companion guide to a first course in Linear Algebra at the university level, which demonstrates how to use computational tools in practice, while you learn the theory in your course.

For those interested in working with linear algebra with numerical tools - i.e. floating point numerical data (engineering, data science, etc.) you'll be interested in doing this through the NumPy package (along with SciPy). (Num = Numerical, Sci = Scientific)

NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays - such as tools from linear algebra.

SciPy is a free and open-source Python library (built on top of Numpy) used for scientific computing and technical computing. SciPy contains modules for optimization, linear algebra, integration, interpolation, special functions, FFT, signal and image processing, ODE solvers and other tasks common in science and engineering. This is in the flavour of MatLab.

For those interested in using linear algebra in a symbolic setting, or for working with matrices over the integers or rational numbers (not float point numbers) you'll be interested in using the SymPy package. (Sym = Symbolic)

SymPy is an open-source Python library for symbolic computation. It provides computer algebra capabilities in the flavour of Maple.

In the menu on the left you can choose your "flavour".

For a list of how python can be used in your other mathematics courses see

https://www.sfu.ca/~jtmulhol/py4math

Also, see this page if you need a crash courses in python, numpy, or matplotlib.