mlx.core.linalg.eig#
- eig(a: array, *, stream: Optional[Union[Stream, Device]] = None) tuple #
Compute the eigenvalues and eigenvectors of a square matrix.
This function differs from
numpy.linalg.eig()
in that the return type is always complex even if the eigenvalues are all real.This function supports arrays with at least 2 dimensions. When the input has more than two dimensions, the eigenvalues and eigenvectors are computed for each matrix in the last two dimensions.
- Parameters:
- Returns:
A tuple containing the eigenvalues and the normalized right eigenvectors. The column
v[:, i]
is the eigenvector corresponding to the i-th eigenvalue.- Return type:
Example
>>> A = mx.array([[1., -2.], [-2., 1.]]) >>> w, v = mx.linalg.eig(A, stream=mx.cpu) >>> w array([3+0j, -1+0j], dtype=complex64) >>> v array([[0.707107+0j, 0.707107+0j], [-0.707107+0j, 0.707107+0j]], dtype=complex64)