Creating a sparse or blackbox matrix in Sage
-
25-10-2019 - |
Question
It seems to me that in Sage the only difference between creating a dense matrix and a sparse matrix is by the flag passed to the constructor ("sparse=True"). In particular, this means that if I want to create a sparse matrix of size 200,000 x 200,000 but only 500,000 nonzero entries I need first to create a list of size 40,000,000,000, which is absurd. Is there a better way?
Also, as I'm only interested in solving a linear equation system defined by the matrix, I can be satisfied with using a "black box" representation (i.e. give a function g such that g(v)=Av with A being the matrix). This is supported in the underlying LinBox library, but I have no idea what the corresponding Sage interface is.
Solution
Use a dictionary to specify sparse matrices
matrix(5000,5000,{(1,2): 1})
OTHER TIPS
And see the Sage reference manual for lots more examples of matrix constructors.