# 在Python中找到2个最大的稀疏矩阵最大特征值[关闭]Finding 2 largest eigenvalues of large-sparse matrix in Python [closed]

## 1 个回复1

### ===============>>#1 票数：1 已采纳

tl; dr：您可以按照文档中所述使用`which='LA'`标志。

scipy.sparse.linalg.eigsh（A，k = 6，M = None，sigma = None， which ='LM' ，v0 = None，ncv = None，maxiter = None，tol = 0，return_eigenvectors = True，Minv =无，OPinv =无，模式=“正常”）

``````which : str [‘LM’ | ‘SM’ | ‘LA’ | ‘SA’ | ‘BE’]
If A is a complex hermitian matrix, ‘BE’ is invalid. Which k eigenvectors and eigenvalues to find:
‘LM’ : Largest (in magnitude) eigenvalues
‘SM’ : Smallest (in magnitude) eigenvalues
‘LA’ : Largest (algebraic) eigenvalues
‘SA’ : Smallest (algebraic) eigenvalues
‘BE’ : Half (k/2) from each end of the spectrum
``````

``````In [19]: A = numpy.random.randn(5,5)

In [20]: numpy.linalg.eig(A+A.T)[0] #Actual Eigenvalues
Out[20]: array([ 3.32906012,  0.88700157, -1.16620472, -3.54512752, -2.43562899])

In [21]: sp.eigsh(A+A.T,3)[0] #Three Largest (in Magnitude). What you don't want
Out[21]: array([-3.54512752, -2.43562899,  3.32906012])

In [22]: sp.eigsh(A+A.T,3,which='LA')[0] #Three Largest. What you do want

Out[22]: array([-1.16620472,  0.88700157,  3.32906012])
``````

2回复

1回复

1回复

1回复

1回复

2回复

1回复

1回复

2回复

1回复