Linear algebra with NumPy

Linear algebra is an important subdivision of mathematics. We can use linear algebra, for instance, to perform linear regression. The numpy.linalg subpackage holds linear algebra routines. With this subpackage, you can invert matrices, compute eigenvalues, solve linear equations, and find determinants, among other things. Matrices in NumPy are represented by a subclass of ndarray.

Inverting matrices with NumPy

The inverse of a square and invertible matrix A in linear algebra is the matrix A-1, which, when multiplied with the original matrix, is equal to the identity matrix I. This can be written down as the following mathematical equation:

A A-1 = I 

The inv() function in the numpy.linalg subpackage can do this for us. Let's ...

Get Python Data Analysis - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.