2

I am starting to use the scipy.sparse library, and when I try to apply scipy.sparse.linalg.svds, I get an error if there are zero singular values.

I am doing this because in the end I am going to use very large and very sparse matrices with entries only {+1, -1} which are not square (>1100*1000 size with >0.99 sparsity), and I want to know their rank. I know approximately what the rank is, it is almost full, so knowing only the last singular values can tell me what is the rank exactly.

This is why I chose to work with scipy.sparse.linalg.svds and set which='LM'. If the rank is not full, there will be singular values which are zero, this is my code:

import numpy as np 
import scipy.sparse as sp
import scipy.sparse.linalg as la

a = np.array([[0, 0, 0], [0, 0, 0], [1, 1, -1]], dtype='d')
sp_a = sp.csc_matrix(a)
s = la.svds(sp_a, k=2, return_singular_vectors=False, which='SM')
print(s)

output is

[           nan 9.45667059e-12]

/usr/lib/python3/dist-packages/scipy/sparse/linalg/eigen/arpack/arpack.py:1849: RuntimeWarning: invalid value encountered in sqrt s = np.sqrt(eigvals)

Any thoughts on why this happens? Maybe there is another efficient way to know the rank, knowing that I have a large non-square very sparse matrix with almost full rank?

scipy version 1.1.0 numpy version 1.14.5 Linux platform

Thanks in advance

Amir
  • 21
  • 3

0 Answers0