When a sparse matrix is generated by scipy.sparse.rand, it can be singular. In fact,the below code raises an error "RuntimeError: superlu failure (singular matrix?) at line 100 in file scipy/sparse/linalg/dsolve/SuperLU/SRC/dsnode_bmod.c".
dim = 20000
ratio = 0.000133
A = scipy.sparse.rand(dim,dim,ratio)
inv_sparse = scipy.sparse.linalg.inv(A)
Is there a way to generate non-singular sparse matrix?
What I really want to do is comparing performance (process time) of scipy.sparse.linalg.inv with np.linalg.inv. That's why I need generate random sparse matrix which is not singular.
sparse.eye(A.shape[0])to it.