://sun.stanford.edu/~rmunk/PROPACK (2004): 2008-2009. Examples -------- Construct a matrix ``A`` from singular values and vectors. >>> import numpy as np >>> from scipy.stats import ortho_group >>> from scipy.sparse import csc_array, diags_array >>> from scipy.sparse.linalg import svds >>> rng = np.random.default_rng() >>> orthogonal = csc_array(ortho_group.rvs(10, random_state=rng)) >>> s = [0.0001, 0.001, 3, 4, 5] # singular values >>> u = orthogonal[:, :5] # left singular vectors >>> vT = orthogonal[:, 5:].T # right singular vectors >>> A = u @ diags_array(s) @ vT With only three singular values/vectors, the SVD approximates the original matrix. >>> u2, s2, vT2 = svds(A, k=3, solver='propack') >>> A2 = u2 @ np.diag(s2) @ vT2 >>> np.allclose(A2, A.todense(), atol=1e-3) True With all five singular values/vectors, we can reproduce the original matrix. >>> u3, s3, vT3 = svds(A, k=5, solver='propack') >>> A3 = u3 @ np.diag(s3) @ vT3 >>> np.allclose(A3, A.todense()) True The singular values match the expected singular values, and the singular vectors are as expected up to a difference in sign. >>> (np.allclose(s3, s) and ... np.allclose(np.abs(u3), np.abs(u.toarray())) and ... np.allclose(np.abs(vT3), np.abs(vT.toarray()))) True The singular vectors are also orthogonal. >>> (np.allclose(u3.T @ u3, np.eye(5)) and ... np.allclose(vT3 @ vT3.T, np.eye(5))) True Nr