pinv

paddle.linalg. pinv ( x: Tensor, rcond: float | Tensor = 1e-15, hermitian: bool = False, name: str | None = None ) Tensor [source]

Calculate pseudo inverse via SVD(singular value decomposition) of one matrix or batches of regular matrix.

\[if hermitian == False: x = u * s * vt (SVD) out = v * 1/s * ut else: x = u * s * ut (eigh) out = u * 1/s * u.conj().transpose(-2,-1)\]

If x is hermitian or symmetric matrix, svd will be replaced with eigh.

Parameters
  • x (Tensor) – The input tensor. Its shape should be (*, m, n) where * is zero or more batch dimensions. m and n can be arbitrary positive number. The data type of x should be float32 or float64 or complex64 or complex128. When data type is complex64 or complex128, hermitian should be set True.

  • rcond (Tensor|float, optional) – the tolerance value to determine when is a singular value zero. Default:1e-15.

  • hermitian (bool, optional) – indicates whether x is Hermitian if complex or symmetric if real. Default: False.

  • name (str|None, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to api_guide_Name.

Returns

The tensor with same data type with x. it represents pseudo inverse of x. Its shape should be (*, n, m).

Return type

Tensor

Examples

>>> import paddle

>>> x = paddle.arange(15).reshape((3, 5)).astype('float64')
>>> input = paddle.to_tensor(x)
>>> out = paddle.linalg.pinv(input)
>>> print(input)
Tensor(shape=[3, 5], dtype=float64, place=Place(cpu), stop_gradient=True,
[[0. , 1. , 2. , 3. , 4. ],
 [5. , 6. , 7. , 8. , 9. ],
 [10., 11., 12., 13., 14.]])

>>> print(out)
Tensor(shape=[5, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
[[-0.22666667, -0.06666667,  0.09333333],
 [-0.12333333, -0.03333333,  0.05666667],
 [-0.02000000, -0.00000000,  0.02000000],
 [ 0.08333333,  0.03333333, -0.01666667],
 [ 0.18666667,  0.06666667, -0.05333333]])

# one can verify : x * out * x = x ;
# or              out * x * out = x ;