#NEWLINE# def pinv2( a , cond = None , rcond = None , return_rank = False , check_finite = True ) : #NEWLINE# #INDENT# "\n    Compute the (Moore-Penrose) pseudo-inverse of a matrix.\n\n    Calculate a generalized inverse of a matrix using its\n    singular-value decomposition and including all 'large' singular\n    values.\n\n    Parameters\n    ----------\n    a : (M, N) array_like\n        Matrix to be pseudo-inverted.\n    cond, rcond : float or None\n        Cutoff for 'small' singular values.\n        Singular values smaller than ``rcond*largest_singular_value``\n        are considered zero.\n        If None or -1, suitable machine precision is used.\n    return_rank : bool, optional\n        if True, return the effective rank of the matrix\n    check_finite : bool, optional\n        Whether to check that the input matrix contains only finite numbers.\n        Disabling may give a performance gain, but may result in problems\n        (crashes, non-termination) if the inputs do contain infinities or NaNs.\n\n    Returns\n    -------\n    B : (N, M) ndarray\n        The pseudo-inverse of matrix `a`.\n    rank : int\n        The effective rank of the matrix.  Returned if return_rank == True\n\n    Raises\n    ------\n    LinAlgError\n        If SVD computation does not converge.\n\n    Examples\n    --------\n    >>> from scipy import linalg\n    >>> a = np.random.randn(9, 6)\n    >>> B = linalg.pinv2(a)\n    >>> np.allclose(a, np.dot(a, np.dot(B, a)))\n    True\n    >>> np.allclose(B, np.dot(B, np.dot(a, B)))\n    True\n\n    " #NEWLINE# a = _asarray_validated ( a , check_finite = check_finite ) #NEWLINE# ( u , s , vh ) = decomp_svd . svd ( a , full_matrices = False , check_finite = False ) #NEWLINE# if ( rcond is not None ) : #NEWLINE# #INDENT# cond = rcond #NEWLINE# #UNINDENT# if ( cond in [ None , ( - 1 ) ] ) : #NEWLINE# #INDENT# t = u . dtype . char . lower ( ) #NEWLINE# factor = { #NEWLINE# #INDENT# 'f' : 1000.0 , #NEWLINE# 'd' : 1000000.0 , #NEWLINE# #UNINDENT# } #NEWLINE# cond = ( factor [ t ] * np . finfo ( t ) . eps ) #NEWLINE# #UNINDENT# rank = np . sum ( ( s > ( cond * np . max ( s ) ) ) ) #NEWLINE# u = u [ : , : rank ] #NEWLINE# u /= s [ : rank ] #NEWLINE# B = np . transpose ( np . conjugate ( np . dot ( u , vh [ : rank ] ) ) ) #NEWLINE# if return_rank : #NEWLINE# #INDENT# return ( B , rank ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return B