mindspore.ops.pinv
- mindspore.ops.pinv(x, *, atol=None, rtol=None, hermitian=False)[source]
Computes the (Moore-Penrose) pseudo-inverse of a matrix. This function is computed using SVD. If
,Than the pseudo-inverse of x is: , is the reciprocal of each non-zero element on the diagonal of S, and zero remains in place. Batch matrices are supported. If x is a batch matrix, the output has the same batch dimension when atol or rtol is float. If atol or rtol is a Tensor, its shape must be broadcast to the singular value returned by x.svd . If x.shape is , and the shape of atol or rtol is , the output shape is . When the Hermitian is True, temporary support only real domain, x is treated as a real symmetric, so x is not checked internally, and only use the lower triangular part in the computations. When the singular value of x (or the norm of the eigenvalues when hermitian = True) that are below threshold ( , as the largest singular value or characteristic value), it is set to zero, and is not used in the computations. If rtol is not specified and x is a matrix of dimensions (M, N), then rtol is set to be , is the eps value of x.dtype. If rtol is not specified and atol specifies a value larger than zero, rtol is set to zero.Note
This function uses svd internally, (or eigh , when hermitian = True ). So it has the same problem as these functions. For details, see the warnings in svd() and eigh().
- Parameters
x (Tensor) –
A matrix to be calculated. Only float32, float64 are supported Tensor dtypes. shape is
, * is zero or more batch dimensions.When hermitian is
True
, batch dimensions are not supported temporarily.
- Keyword Arguments
- Outputs:
output (Tensor) - same type as input. Shape is
, * is zero or more batch dimensions.
- Raises
TypeError – If hermitian is not a bool.
TypeError – If x is not a Tensor.
ValueError – If the dimension of x is less than 2.
- Supported Platforms:
CPU
Examples
>>> import mindspore >>> from mindspore import Tensor, ops >>> x = Tensor([[4., 0.], [0., 5.]], mindspore.float32) >>> output = ops.pinv(x) >>> print(output) [[0.25 0. ] [0. 0.2 ]]