dpnp.linalg.eig

dpnp.linalg.eig(a)[source]

Compute the eigenvalues and right eigenvectors of a square array.

For full documentation refer to numpy.linalg.eig.

Parameters:

a ((..., M, M) {dpnp.ndarray, usm_ndarray}) -- Matrices for which the eigenvalues and right eigenvectors will be computed.

Returns:

A namedtuple with the following attributes
  • eigenvalues ((..., M) dpnp.ndarray) -- The eigenvalues, each repeated according to its multiplicity. The eigenvalues are not necessarily ordered. The resulting array is always of complex type, even when a is real-valued. In that case the eigenvalues either have a zero imaginary part or occur in conjugate pairs.

  • eigenvectors ((..., M, M) dpnp.ndarray) -- The normalized (unit "length") eigenvectors, such that the column eigenvectors[:,i] is the eigenvector corresponding to the eigenvalue eigenvalues[i].

Note

Since there is no proper OneMKL LAPACK function, DPNP will calculate through a fallback on NumPy call.

See also

dpnp.linalg.eigvals

Compute the eigenvalues of a general matrix.

dpnp.linalg.eigh

Return the eigenvalues and eigenvectors of a complex Hermitian (conjugate symmetric) or a real symmetric matrix.

dpnp.linalg.eigvalsh

Compute the eigenvalues of a complex Hermitian or real symmetric matrix.

Examples

>>> import dpnp as np
>>> from dpnp import linalg as LA

(Almost) trivial example with real eigenvalues and eigenvectors.

>>> w, v = LA.eig(np.diag((1, 2, 3)))
>>> w, v.real
(array([1.+0.j, 2.+0.j, 3.+0.j]),
 array([[1., 0., 0.],
        [0., 1., 0.],
        [0., 0., 1.]]))

Real matrix possessing complex eigenvalues and eigenvectors; note that the eigenvalues are complex conjugates of each other.

>>> w, v = LA.eig(np.array([[1, -1], [1, 1]]))
>>> w, v
(array([1.+1.j, 1.-1.j]),
 array([[0.70710678+0.j        , 0.70710678-0.j        ],
        [0.        -0.70710678j, 0.        +0.70710678j]]))

Complex-valued matrix with real eigenvalues (but complex-valued eigenvectors); note that a.conj().T == a, i.e., a is Hermitian.

>>> a = np.array([[1, 1j], [-1j, 1]])
>>> w, v = LA.eig(a)
>>> w, v
(array([2.+0.j, 0.+0.j]),
 array([[ 0.        +0.70710678j,  0.70710678+0.j        ], # may vary
        [ 0.70710678+0.j        , -0.        +0.70710678j]])

Be careful about round-off error!

>>> a = np.array([[1 + 1e-9, 0], [0, 1 - 1e-9]])
>>> # Theor. eigenvalues are 1 +/- 1e-9
>>> w, v = LA.eig(a)
>>> w, v.real
(array([1.+0.j, 1.+0.j]),
 array([[1., 0.],
        [0., 1.]]))