Matrices are usually classified into two different structures: dense matrices and sparse matrices. A dense matrix is composed of mostly non-zero elements. A sparse matrix is a matrix that is mostly composed of elements with a 0 value. The sparsity of a matrix is calculated as the number of elements with a zero value divided by the total count of elements.
If the result of this equation is greater than 0.5, the matrix is sparse. This distinction is important as it helps us to determine the best method for matrix manipulation. If a matrix is sparse, we may be able to use some optimizations to make the matrix manipulation more efficient. Inversely, if we have a dense matrix, we know that we will most likely be performing actions on the whole matrix.
It is important to remember that operations on matrices are most likely going to be memory bound with...