문제

I have a symmetric matrix (adjacency matrix for an undirected graph) and I have a particular eigenvalue (the maximum eigenvalue) and I want the eigenvector associated with it (left or right, either one, since I believe the left is simply the transpose of the right for symmetric matrices).

The graphs I am running can go from thousands to hundreds of thousands of nodes so the corresponding adjacency matrix will be large. The density however is sparse, so the corresponding matrix will be sparse as well.

Is there an efficient way to do this in SciPy? Better yet, is there a way to compute only the leading eigenvalue and the corresponding eigenvector for a given symmetric matrix (meaning I don't have to compute the leading eigenvalue myself explicitly with linalg.eigvals).

도움이 되었습니까?

해결책

Yes there is, scipy.sparse.linalg.eigsh, the h at the end standing for Hermitian, there is also a version for non-symmetrical matrices, scipy.sparse.linalg.eigs.

If a is your matrix, sparse or not, your call would look something like:

evals, evecs = scipy.sparse.linalg.eigsh(a, k=1)

Your evals and evecs are arrays of eigenvalues and corresponding eigenvectors, since you could ask for more than one if setting k to something other than 1. Which eigenvalues and vectors are returned is controlled with the which parameter, that defaults to LM, standing for largest magnitude.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top