eigh#
- ivy.eigh(x, /, *, UPLO='L', out=None)[source]#
Return an eigendecomposition x = QLQᵀ of a symmetric matrix (or a stack of symmetric matrices)
x
, whereQ
is an orthogonal matrix (or a stack of matrices) andL
is a vector (or a stack of vectors).Note
The function
eig
will be added in a future version of the specification, as it requires complex number support, once complex numbers are supported, each square matrix must be Hermitian.Note
Whether an array library explicitly checks whether an input array is a symmetric matrix (or a stack of symmetric matrices) is implementation-defined.
- Parameters:
x (
Union
[Array
,NativeArray
]) – input array having shape(..., M, M)
and whose innermost two dimensions form square matrices. Must have a floating-point data type.- Return type:
Tuple
[Union
[Array
,NativeArray
]]- Returns:
ret – a namedtuple (
eigenvalues
,eigenvectors
) whosefirst element must have the field name
eigenvalues
(corresponding to \(\operatorname{diag}\Lambda\) above) and must be an array consisting of computed eigenvalues. The array containing the eigenvalues must have shape(..., M)
and must have a real-valued floating-point data type whose precision matches the precision ofx
(e.g., ifx
iscomplex128
, then theeigenvalues
must befloat64
).second element have have the field name
eigenvectors
(corresponding toQ
above) and must be an array where the columns of the inner most matrices contain the computed eigenvectors. These matrices must be orthogonal. The array containing the eigenvectors must have shape(..., M, M)
.Each returned array must have the same floating-point data type as
x
.
.. note:: – Eigenvalue sort order is left unspecified and is thus implementation-dependent.
This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.
Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.Examples
With
ivy.Array
input:>>> x = ivy.array([[1., 2.],[2., 5.]]) >>> eigenvalues, eigenvectors = ivy.eigh(x) >>> print(eigenvalues) ivy.array([0.17157288, 5.82842731]) >>> print(eigenvectors) ivy.array([[-0.9238795 , 0.38268343], [ 0.38268343, 0.9238795 ]])
>>> x = ivy.array([[1., 2.], [2., 5.]]) >>> eigenvalues, eigenvectors = ivy.zeros(len(x)), ivy.zeros(x.shape) >>> ivy.eigh(x, out=(eigenvalues, eigenvectors)) >>> print(eigenvalues) ivy.array([0.17157288, 5.82842731]) >>> print(eigenvectors) ivy.array([[-0.9238795 , 0.38268343], [ 0.38268343, 0.9238795 ]])
With
ivy.Container
input:>>> x = ivy.Container( ... a = ivy.native_array([[1., 2., 0.], [3., 4., 5.], [1., 5., 9]]), ... b = ivy.array([[2., 4., 6.], [3., 5., 7.], [0., 0.8, 2.9]])) >>> eigenvalues, eigenvectors = ivy.eigh(x, UPLO = 'U') >>> print(eigenvalues) { a: ivy.array([-0.78930789, 2.59803128, 12.19127655]), b: ivy.array([-4.31213903, -0.63418275, 14.84632206]) } >>> print(eigenvectors) { a: ivy.array([[0.70548367, -0.70223427, 0.09570674], [-0.63116378, -0.56109613, 0.53554028], [0.32237405, 0.43822157, 0.83906901]]), b: ivy.array([[0.50766778, 0.71475857, 0.48103389], [0.3676433, -0.68466955, 0.62933773], [-0.77917379, 0.14264561, 0.61036086]]) }
- Container.eigh(self, /, *, UPLO='L', key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.eigh. This method simply wraps the function, and so the docstring for ivy.eigh also applies to this method with minimal changes.
- Parameters:
self (ivy.Container) – Ivy container having shape (…, M, M) and whose innermost two dimensions form square matrices. Should have a floating-point data type.
UPLO (str, optional) – Specifies whether the upper or lower triangular part of the Hermitian matrix should be used for the eigenvalue decomposition. Default is ‘L’.
key_chains (Union[List[str], Dict[str, str]], optional) – The key-chains to apply or not apply the method to. Default is None.
to_apply (bool, optional) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.
prune_unapplied (bool, optional) – Whether to prune key_chains for which the function was not applied. Default is False.
map_sequences (bool, optional) – Whether to also map method to sequences (lists, tuples). Default is False.
out (ivy.Container, optional) – Optional output container, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ivy.Container – A container containing the computed eigenvalues. The returned array must have shape (…, M) and have the same data type as self.
Examples
With ivy.Container inputs:
>>> x = ivy.Container(a=ivy.array([[[1.,2.],[2.,1.]]]), ... b=ivy.array([[[2.,4.],[4.,2.]]])) >>> y = x.eigh() >>> print(y) { a: ivy.array([[-1., 3.]]), b: ivy.array([[-2., 6.]]) }