[SciPy-user] Sparse v. dense matrix, SVD and LSI-like analysis

Nick Arnett narnett at mccmedia.com
Wed Nov 17 14:04:40 CST 2004


Travis Oliphant wrote:

> So, while the SVD is not an eigenvector decomposition it is related to one.

Right... but I still don't understand the statement, "In any case, all 
of the linalg.* functions only operate on dense arrays, not sparse 
matrices."

Why would linalg.svd not operate on a sparse matrix?  I was working from 
the example (below) from your Scipy tutorial, in fact.  Would the 
results not be meaningful if the matrix is sparse?

>>>> A = mat('[1 3 2; 1 2 3]')
>>>> M,N = A.shape
>>>> U,s,Vh = linalg.svd(A)
>>>> Sig = mat(diagsvd(s,M,N))
>>>> U, Vh = mat(U), mat(Vh)
>>>> print U
> Matrix([[-0.7071, -0.7071],
> [-0.7071, 0.7071]])
>>>> print Sig
> Matrix([[ 5.1962, 0. , 0. ],
> [ 0. , 1. , 0. ]])
>>>> print Vh
> Matrix([[-0.2722, -0.6804, -0.6804],
> [-0. , -0.7071, 0.7071],
> [-0.9623, 0.1925, 0.1925]])
>>>> print A
> Matrix([[1, 3, 2],
> [1, 2, 3]])
>>>> print U*Sig*Vh
> Matrix([[ 1., 3., 2.],
> [ 1., 2., 3.]])


Thanks!

Nick



More information about the SciPy-user mailing list