Computations on top of a sparse matrix

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 with the sparse matrix and another time without the sparse matrix format
  • Compare the differences in the speed of computation by using the sparse matrix format
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset