def eig(a, b=None, left=False, right=True, overwrite_a=False,<EOL>overwrite_b=False, check_finite=True):
if check_finite:<EOL><INDENT>a1 = asarray_chkfinite(a)<EOL><DEDENT>else:<EOL><INDENT>a1 = asarray(a)<EOL><DEDENT>if len(a1.shape) != <NUM_LIT:2> or a1.shape[<NUM_LIT:0>] != a1.shape[<NUM_LIT:1>]:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>overwrite_a = overwrite_a or (_datacopied(a1, a))<EOL>if b is not None:<EOL><INDENT>if check_finite:<EOL><INDENT>b1 = asarray_chkfinite(b)<EOL><DEDENT>else:<EOL><INDENT>b1 = asarray(b)<EOL><DEDENT>overwrite_b = overwrite_b or _datacopied(b1, b)<EOL>if len(b1.shape) != <NUM_LIT:2> or b1.shape[<NUM_LIT:0>] != b1.shape[<NUM_LIT:1>]:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if b1.shape != a1.shape:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return _geneig(a1, b1, left, right, overwrite_a, overwrite_b)<EOL><DEDENT>geev, geev_lwork = get_lapack_funcs(('<STR_LIT>', '<STR_LIT>'), (a1,))<EOL>compute_vl, compute_vr = left, right<EOL>lwork, info = geev_lwork(a1.shape[<NUM_LIT:0>],<EOL>compute_vl=compute_vl,<EOL>compute_vr=compute_vr)<EOL>if info != <NUM_LIT:0>:<EOL><INDENT>raise LinAlgError("<STR_LIT>" % (info,))<EOL><DEDENT>lwork = int(lwork.real)<EOL>if geev.typecode in '<STR_LIT>':<EOL><INDENT>w, vl, vr, info = geev(a1, lwork=lwork,<EOL>compute_vl=compute_vl,<EOL>compute_vr=compute_vr,<EOL>overwrite_a=overwrite_a)<EOL><DEDENT>else:<EOL><INDENT>wr, wi, vl, vr, info = geev(a1, lwork=lwork,<EOL>compute_vl=compute_vl,<EOL>compute_vr=compute_vr,<EOL>overwrite_a=overwrite_a)<EOL>t = {'<STR_LIT:f>':'<STR_LIT:F>','<STR_LIT:d>':'<STR_LIT:D>'}[wr.dtype.char]<EOL>w = wr + _I * wi<EOL><DEDENT>if info < <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>% -info)<EOL><DEDENT>if info > <NUM_LIT:0>:<EOL><INDENT>raise LinAlgError("<STR_LIT>"<EOL>"<STR_LIT>" % info)<EOL><DEDENT>only_real = numpy.logical_and.reduce(numpy.equal(w.imag, <NUM_LIT:0.0>))<EOL>if not (geev.typecode in '<STR_LIT>' or only_real):<EOL><INDENT>t = w.dtype.char<EOL>if left:<EOL><INDENT>vl = _make_complex_eigvecs(w, vl, t)<EOL><DEDENT>if right:<EOL><INDENT>vr = _make_complex_eigvecs(w, vr, t)<EOL><DEDENT><DEDENT>if not (left or right):<EOL><INDENT>return w<EOL><DEDENT>if left:<EOL><INDENT>if right:<EOL><INDENT>return w, vl, vr<EOL><DEDENT>return w, vl<EOL><DEDENT>return w, vr<EOL>
Solve an ordinary or generalized eigenvalue problem of a square matrix.

Find eigenvalues w and right or left eigenvectors of a general matrix::

    a   vr[:,i] = w[i]        b   vr[:,i]
    a.H vl[:,i] = w[i].conj() b.H vl[:,i]

where ``.H`` is the Hermitian conjugation.

Parameters
----------
a : (M, M) array_like
    A complex or real matrix whose eigenvalues and eigenvectors
    will be computed.
b : (M, M) array_like, optional
    Right-hand side matrix in a generalized eigenvalue problem.
    Default is None, identity matrix is assumed.
left : bool, optional
    Whether to calculate and return left eigenvectors.  Default is False.
right : bool, optional
    Whether to calculate and return right eigenvectors.  Default is True.
overwrite_a : bool, optional
    Whether to overwrite `a`; may improve performance.  Default is False.
overwrite_b : bool, optional
    Whether to overwrite `b`; may improve performance.  Default is False.
check_finite : boolean, 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.

Returns
-------
w : (M,) double or complex ndarray
    The eigenvalues, each repeated according to its multiplicity.
vl : (M, M) double or complex ndarray
    The normalized left eigenvector corresponding to the eigenvalue
    ``w[i]`` is the column vl[:,i]. Only returned if ``left=True``.
vr : (M, M) double or complex ndarray
    The normalized right eigenvector corresponding to the eigenvalue
    ``w[i]`` is the column ``vr[:,i]``.  Only returned if ``right=True``.

Raises
------
LinAlgError
    If eigenvalue computation does not converge.

See Also
--------
eigh : Eigenvalues and right eigenvectors for symmetric/Hermitian arrays.