Python: equivalent to Matlab svds (A, k) for large arrays?

I am trying to port some code from Matlab to Python and I am having a problem. I can not find the equivalent of svds.

I tried using numpy.corrcoef and then numpy.linalg.eig, but numpy.corrcoef does not work for large arrays (say 500 x 20,000).

Here's the code in matlab, if it matters:

s = size(data, 2)
mean = sum(data, 2)/s
m_data = ( data - repmat(mean, 1, s) ) / sqrt(s - 1)
[res_u,res_s] = svds(m_data, s)
eigenvals = diag(res_s).^2
eigenvecs = res_u
+5
source share
2 answers

, , - python numpy ( " " matlab - python numpy, , "" pythonic [the'course matlab):

import numpy as np

def _cas(D):
    """Center at mean and standardize."""
    return (D- D.mean(1)[:, None])/ (D.shape[1]- 1)** .5

def example(D):
    """Eigenvalues and -vectors, based on SVD."""
    u, s, v= np.linalg.svd(D, full_matrices= False);
    return np.diag(s)** 2, u

if __name__ == '__main__':
    data= np.random.rand(5, 20)
    data= _cas(data) # preprocess data according to your requirements
    eigenvals, eigenvecs= example(data)
    print eigenvals
    print eigenvecs

?

, ? FTIW , (500, 20000) example(.) 20 .

(- ) , 2,5 ( 10- )! , , , , , "" data!

? -vectors? .. ?

+3

, scipy.sparse.linalg.svds scipy. SVD ARPACK. , ( , scipy ARPACK), , , .

, 500 20000 , . numpy.linalg.svd full_matrices=False, ?

numpy.corrcoef ? MATLAB .

+2

All Articles