PyTorch torch.pinverse function
PyTorch torch reference manual
torch.pinverse is a function in PyTorch used to compute the Moore-Penrose pseudoinverse of a matrix. It is torch.linalg.pinv is an alias of.
Function definition
torch.pinverse(input, rcond=1e-15)
Parameters:
input(Tensor): Input matrix.rcond(float, optional): Singular value truncation threshold. Default is 1e-15.
Return Value:
torch.Tensor: Returns the pseudoinverse of the matrix.
Usage examples
Example
import
torch
Create a non-square matrix
A
=
torch.
tensor
(
[
[
1.0
,
2.0
,
3.0
]
,
[
4.0
,
5.0
,
6.0
]
]
,
dtype
=
torch.
float64
)
Compute the pseudoinverse
A_pinv
=
torch.
pinverse
(
A
)
(
"Matrix A:"
)
(
A
)
(
"nPseudoinverse A^+:"
)
(
A_pinv
)
The output is:
矩阵 A:
tensor([[1., 2., 3.],
[4., 5., 6.]], dtype=torch.float64)
伪逆 A^+:
tensor([[-0.9444, 0.4444],
[-0.2778, 0.2778],
[ 0.3889, 0.1111]], dtype=float64)