def inv(A):
I = speye(A.shape[<NUM_LIT:0>], A.shape[<NUM_LIT:1>], dtype=A.dtype, format=A.format)<EOL>Ainv = spsolve(A, I)<EOL>return Ainv<EOL>
Compute the inverse of a sparse matrix

Parameters
----------
A : (M,M) ndarray or sparse matrix
    square matrix to be inverted

Returns
-------
Ainv : (M,M) ndarray or sparse matrix
    inverse of `A`

Notes
-----
This computes the sparse inverse of `A`.  If the inverse of `A` is expected
to be non-sparse, it will likely be faster to convert `A` to dense and use
scipy.linalg.inv.

.. versionadded:: 0.12.0