numpy.linalg.eigvalsh#

linalg.eigvalsh(a,UPLO='L')[source]#

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

Main difference from eigh: the eigenvectors are not computed.

Parameters:
a(…, M, M) array_like

A complex- or real-valued matrix whose eigenvalues are to becomputed.

UPLO{‘L’, ‘U’}, optional

Specifies whether the calculation is done with the lower triangularpart ofa (‘L’, default) or the upper triangular part (‘U’).Irrespective of this value only the real parts of the diagonal willbe considered in the computation to preserve the notion of a Hermitianmatrix. It therefore follows that the imaginary part of the diagonalwill always be treated as zero.

Returns:
w(…, M,) ndarray

The eigenvalues in ascending order, each repeated according toits multiplicity.

Raises:
LinAlgError

If the eigenvalue computation does not converge.

See also

eigh

eigenvalues and eigenvectors of real symmetric or complex Hermitian (conjugate symmetric) arrays.

eigvals

eigenvalues of general real or complex arrays.

eig

eigenvalues and right eigenvectors of general real or complex arrays.

scipy.linalg.eigvalsh

Similar function in SciPy.

Notes

Broadcasting rules apply, see thenumpy.linalg documentation fordetails.

The eigenvalues are computed using LAPACK routines_syevd,_heevd.

Examples

>>>importnumpyasnp>>>fromnumpyimportlinalgasLA>>>a=np.array([[1,-2j],[2j,5]])>>>LA.eigvalsh(a)array([ 0.17157288,  5.82842712]) # may vary
>>># demonstrate the treatment of the imaginary part of the diagonal>>>a=np.array([[5+2j,9-2j],[0+2j,2-1j]])>>>aarray([[5.+2.j, 9.-2.j],       [0.+2.j, 2.-1.j]])>>># with UPLO='L' this is numerically equivalent to using LA.eigvals()>>># with:>>>b=np.array([[5.+0.j,0.-2.j],[0.+2.j,2.-0.j]])>>>barray([[5.+0.j, 0.-2.j],       [0.+2.j, 2.+0.j]])>>>wa=LA.eigvalsh(a)>>>wb=LA.eigvals(b)>>>waarray([1., 6.])>>>wbarray([6.+0.j, 1.+0.j])
On this page