This is not a complete answer, but hopefully this will be the starting point for one thing. You should be able to calculate empty space using a variant of the SVD-based approach shown for dense matrices in this question :
import numpy as np from scipy import sparse import scipy.sparse.linalg def rand_rank_k(n, k, **kwargs): "generate a random (n, n) sparse matrix of rank <= k" a = sparse.rand(n, k, **kwargs) b = sparse.rand(k, n, **kwargs) return a.dot(b)
If you know that x is a single line vector, then in principle you will need to calculate the smallest value of a single value / vector M. This should be possible with scipy.sparse.linalg.svds , scipy.sparse.linalg.svds .:
u, s, vh = sparse.linalg.svds(M, k=1, which='SM') null_space = vh.conj().ravel()
Unfortunately, scipy svds seems to behave badly when finding small singular values of singular or almost singular matrices and usually either returns NaNs or throws an ArpackNoConvergence error.
Currently, I don’t know an alternative implementation of truncated SVD with Python bindings that will work on sparse matrices and can selectively find the smallest singular values - maybe someone knows about this?
Edit
As a side note, the second approach works quite well using MATLAB or Octave svds :
>> M = rand(100, 99) * rand(99, 100); % svds converges much more reliably if you set sigma to something small but nonzero >> [U, S, V] = svds(M, 1, 1E-9); >> max(abs(M * V)) ans = 1.5293e-10