In order to understand how to perform computations on top of a sparse matrix and the resulting benefits thereof, we will be looking at an example and comparing the difference between having a sparse matrix and not having a sparse matrix.
Solving a system of equations
As discussed in the Solving linear systems using matrices recipe, a system of equations is solved using the solve function in scipy.linalg.
In order to compare the difference between sparse matrix computation and non-sparse matrix computation, we will perform the following tasks:
- Import relevant packages
- Initialize a 10,000 x 10,000 matrix named A
- Impute very few values with some random numbers
- Set the diagonal, so that the rank of matrix is not reduced by a lot
- Initialize a set of values for the output b so that the equation A*x = b is set up
- Solve for the values of x once...