def inv(a):
a, wrap = _makearray(a)<EOL>_assertRankAtLeast2(a)<EOL>_assertNdSquareness(a)<EOL>t, result_t = _commonType(a)<EOL>if a.shape[-<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>return wrap(empty_like(a, dtype=result_t))<EOL><DEDENT>signature = '<STR_LIT>' if isComplexType(t) else '<STR_LIT>'<EOL>extobj = get_linalg_error_extobj(_raise_linalgerror_singular)<EOL>ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)<EOL>return wrap(ainv.astype(result_t))<EOL>
Compute the (multiplicative) inverse of a matrix.

Given a square matrix `a`, return the matrix `ainv` satisfying
``dot(a, ainv) = dot(ainv, a) = eye(a.shape[0])``.

Parameters
----------
a : (..., M, M) array_like
    Matrix to be inverted.

Returns
-------
ainv : (..., M, M) ndarray or matrix
    (Multiplicative) inverse of the matrix `a`.

Raises
------
LinAlgError
    If `a` is not square or inversion fails.

Notes
-----
Broadcasting rules apply, see the `numpy.linalg` documentation for
details.

Examples
--------
>>> from numpy.linalg import inv
>>> a = np.array([[1., 2.], [3., 4.]])
>>> ainv = inv(a)
>>> np.allclose(np.dot(a, ainv), np.eye(2))
True
>>> np.allclose(np.dot(ainv, a), np.eye(2))
True

If a is a matrix object, then the return value is a matrix as well:

>>> ainv = inv(np.matrix(a))
>>> ainv
matrix([[-2. ,  1. ],
        [ 1.5, -0.5]])

Inverses of several matrices can be computed at once:

>>> a = np.array([[[1., 2.], [3., 4.]], [[1, 3], [3, 5]]])
>>> inv(a)
array([[[-2. ,  1. ],
        [ 1.5, -0.5]],
       [[-5. ,  2. ],
        [ 3. , -1. ]]])