I am using the example code on the documenation page for linalg.eigsh
, here:
import scipy.sparse.linalg as sp
import numpy as np
id = np.eye(13)
vals, vecs = sp.eigsh(id, k=6)
len(vals)
# 6
len(vecs)
# 13
I am asking it for 6
eigenvalues (k=6
) and it does return 6, but it gives me 13 (i.e. all) the eigenvectors.
In the documentation, right when it talks about k
, it says:
The number of eigenvalues and eigenvectors desired. k must be smaller than N. It is not possible to compute all eigenvectors of a matrix.
And indeed I thought that the speed of the Lanczos method, underlying eighsh
was due to it finding only a subset of the eigvectors.
So how can it return all the eigenvectors?
You're interpreting the results wrong. The eigenvectors are the columns of vecs
, but you're counting the rows. vecs
has six columns, as expected.