'Calculate the Moore-Penrose pseudoinverse of the matrix.
The Moore-Penrose pseudoinverse exists and is unique for any matrix.
If the matrix is invertible, the pseudoinverse is the same as the
inverse.
Examples
>>> from sympy import Matrix
>>> Matrix([[1, 2, 3], [4, 5, 6]]).pinv()
Matrix([
[-17/18,  4/9],
[  -1/9,  1/9],
[ 13/18, -2/9]])
See Also
inv
pinv_solve
References
.. [1] https://en.wikipedia.org/wiki/Moore-Penrose_pseudoinverse'

def pinv(self):

    A = self
    AH = self.H
    if A.is_zero:
        return AH
    try:
        if (self.rows >= self.cols):
            return ((AH * A).inv() * AH)
        else:
            return (AH * (A * AH).inv())
    except ValueError:
        raise NotImplementedError('Rank-deficient    matrices    are    not    yet    supported.')
