scipy 1.8.0 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesReturnsBackRef
eigh(a, b=None, lower=True, eigvals_only=False, overwrite_a=False, overwrite_b=False, turbo=True, eigvals=None, type=1, check_finite=True, subset_by_index=None, subset_by_value=None, driver=None)

Find eigenvalues array w and optionally eigenvectors array v of array a , where b is positive definite such that for every eigenvalue λ (i-th entry of w) and its eigenvector vi (i-th column of v ) satisfies:

              a @ vi = λ * b @ vi
vi.conj().T @ a @ vi = λ
vi.conj().T @ b @ vi = 1

In the standard problem, b is assumed to be the identity matrix.

Notes

This function does not check the input array for being Hermitian/symmetric in order to allow for representing arrays with only their upper/lower triangular parts. Also, note that even though not taken into account, finiteness check applies to the whole array and unaffected by "lower" keyword.

This function uses LAPACK drivers for computations in all possible keyword combinations, prefixed with sy if arrays are real and he if complex, e.g., a float array with "evr" driver is solved via "syevr", complex arrays with "gvx" driver problem is solved via "hegvx" etc.

As a brief summary, the slowest and the most robust driver is the classical <sy/he>ev which uses symmetric QR. <sy/he>evr is seen as the optimal choice for the most general cases. However, there are certain occasions that <sy/he>evd computes faster at the expense of more memory usage. <sy/he>evx , while still being faster than <sy/he>ev , often performs worse than the rest except when very few eigenvalues are requested for large arrays though there is still no performance guarantee.

For the generalized problem, normalization with respect to the given type argument:

type 1 and 3 :      v.conj().T @ a @ v = w
type 2       : inv(v).conj().T @ a @ inv(v) = w

type 1 or 2  :      v.conj().T @ b @ v  = I
type 3       : v.conj().T @ inv(b) @ v  = I

Parameters

a : (M, M) array_like

A complex Hermitian or real symmetric matrix whose eigenvalues and eigenvectors will be computed.

b : (M, M) array_like, optional

A complex Hermitian or real symmetric definite positive matrix in. If omitted, identity matrix is assumed.

lower : bool, optional

Whether the pertinent array data is taken from the lower or upper triangle of a and, if applicable, b . (Default: lower)

eigvals_only : bool, optional

Whether to calculate only eigenvalues and no eigenvectors. (Default: both are calculated)

subset_by_index : iterable, optional

If provided, this two-element iterable defines the start and the end indices of the desired eigenvalues (ascending order and 0-indexed). To return only the second smallest to fifth smallest eigenvalues, [1, 4] is used. [n-3, n-1] returns the largest three. Only available with "evr", "evx", and "gvx" drivers. The entries are directly converted to integers via int() .

subset_by_value : iterable, optional

If provided, this two-element iterable defines the half-open interval (a, b] that, if any, only the eigenvalues between these values are returned. Only available with "evr", "evx", and "gvx" drivers. Use np.inf for the unconstrained ends.

driver: str, optional :

Defines which LAPACK driver should be used. Valid options are "ev", "evd", "evr", "evx" for standard problems and "gv", "gvd", "gvx" for generalized (where b is not None) problems. See the Notes section. The default for standard problems is "evr". For generalized problems, "gvd" is used for full set, and "gvx" for subset requested cases.

type : int, optional

For the generalized problems, this keyword specifies the problem type to be solved for w and v (only takes 1, 2, 3 as possible inputs):

1 =>     a @ v = w @ b @ v
2 => a @ b @ v = w @ v
3 => b @ a @ v = w @ v

This keyword is ignored for standard problems.

overwrite_a : bool, optional

Whether to overwrite data in a (may improve performance). Default is False.

overwrite_b : bool, optional

Whether to overwrite data in b (may improve performance). Default is False.

check_finite : bool, optional

Whether to check that the input matrices contain only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.

turbo : bool, optional

Deprecated since v1.5.0, use ``driver=gvd`` keyword instead. Use divide and conquer algorithm (faster but expensive in memory, only for generalized eigenvalue problem and if full set of eigenvalues are requested.). Has no significant effect if eigenvectors are not requested.

eigvals : tuple (lo, hi), optional

Deprecated since v1.5.0, use ``subset_by_index`` keyword instead. Indexes of the smallest and largest (in ascending order) eigenvalues and corresponding eigenvectors to be returned: 0 <= lo <= hi <= M-1. If omitted, all eigenvalues and eigenvectors are returned.

Raises

LinAlgError

If eigenvalue computation does not converge, an error occurred, or b matrix is not definite positive. Note that if input matrices are not symmetric or Hermitian, no error will be reported but results will be wrong.

Returns

w : (N,) ndarray

The N (1<=N<=M) selected eigenvalues, in ascending order, each repeated according to its multiplicity.

v : (M, N) ndarray

(if eigvals_only == False )

Solve a standard or generalized eigenvalue problem for a complex Hermitian or real symmetric matrix.

See Also

eig

eigenvalues and right eigenvectors for non-symmetric arrays

eigh_tridiagonal

eigenvalues and right eiegenvectors for symmetric/Hermitian tridiagonal matrices

eigvalsh

eigenvalues of symmetric or Hermitian arrays

Examples

>>> from scipy.linalg import eigh
... A = np.array([[6, 3, 1, 5], [3, 0, 5, 1], [1, 5, 6, 2], [5, 1, 2, 2]])
... w, v = eigh(A)
... np.allclose(A @ v - v @ np.diag(w), np.zeros((4, 4))) True

Request only the eigenvalues

>>> w = eigh(A, eigvals_only=True)

Request eigenvalues that are less than 10.

>>> A = np.array([[34, -4, -10, -7, 2],
...  [-4, 7, 2, 12, 0],
...  [-10, 2, 44, 2, -19],
...  [-7, 12, 2, 79, -34],
...  [2, 0, -19, -34, 29]])
... eigh(A, eigvals_only=True, subset_by_value=[-np.inf, 10]) array([6.69199443e-07, 9.11938152e+00])

Request the largest second eigenvalue and its eigenvector

>>> w, v = eigh(A, subset_by_index=[1, 1])
... w array([9.11938152])
>>> v.shape  # only a single column is returned
(5, 1)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.linalg._decomp.eigvalsh scipy.linalg._decomp.eigvals_banded scipy.linalg._decomp.eigh scipy.linalg._decomp.eigh_tridiagonal scipy.linalg._decomp.eig scipy.linalg._decomp.eig_banded

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/linalg/_decomp.py#267
type: <class 'function'>
Commit: