Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Eigenvectors and eigenspaces show up all over ML (PCA, stability, dynamical systems) and are core linear algebra skills. In this task, you’ll compute the eigenspace dimension(s) for real eigenvalues of a small matrix using NumPy.
An eigenvalue and eigenvector satisfy . The eigenspace corresponding to is the set of all such vectors. The dimension of this space (geometric multiplicity) is given by:
Implement the function
Rules:
tol into a single “distinct” eigenvalue.abs(imag_part) <= tol.Output:
| Argument | Type |
|---|---|
| A | np.ndarray |
| tol | float |
| Return Name | Type |
|---|---|
| value | list |
Use NumPy only; no symbolic math.
Cluster eigenvalues within tol as identical.
Rank via SVD thresholded by tol.
Use np.asarray(A) to ensure the input is a NumPy array, then compute eigenvalues with np.linalg.eigvals. Filter to “real” eigenvalues using abs(ev.imag) <= tol.
Floating-point eigenvalues won’t match exactly—sort the real eigenvalues and cluster/group values that differ by at most tol to form distinct eigenvalues.
For each distinct real (\lambda), form B = A - λI and compute its rank numerically (e.g., via SVD singular values > tol). Then eigenspace dimension is n - rank(B).