pinv#

ivy.pinv(x, /, *, rtol=None, out=None)[source]#

Return the (Moore-Penrose) pseudo-inverse of a matrix (or a stack of matrices) x.

Parameters:
  • x (Union[Array, NativeArray]) – input array having shape (..., M, N) and whose innermost two dimensions form MxN matrices. Should have a floating-point data type.

  • rtol (Optional[Union[float, Tuple[float]]], default: None) – relative tolerance for small singular values. Singular values approximately less than or equal to rtol * largest_singular_value are set to zero. If a float, the value is equivalent to a zero-dimensional array having a floating-point data type determined by type-promotion (as applied to x) and must be broadcast against each matrix. If an array, must have a floating-point data type and must be compatible with shape(x)[:-2] (see broadcasting). If None, the default value is max(M, N) * eps, where eps must be the machine epsilon associated with the floating-point data type determined by type-promotion (as applied to x). Default: None.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array containing the pseudo-inverses. The returned array must have a floating-point data type determined by type-promotion and must have shape (..., N, M) (i.e., must have the same shape as x, except the innermost two dimensions must be transposed).

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

>>> x = ivy.array([[1., 2.],[3., 4.]])
>>> y = ivy.pinv(x)
>>> print(y)
ivy.array([[-1.99999988,  1.        ],
       [ 1.5       , -0.5       ]])
>>> x = ivy.array([[1., 2.],[3., 4.]])
>>> out = ivy.zeros(x.shape)
>>> ivy.pinv(x, out=out)
>>> print(out)
ivy.array([[-1.99999988,  1.        ],
       [ 1.5       , -0.5       ]])
Array.pinv(self, /, *, rtol=None, out=None)[source]#

ivy.Array instance method variant of ivy.pinv. This method simply wraps the function, and so the docstring for ivy.pinv also applies to this method with minimal changes.

Parameters:
  • self (Array) – input array having shape (..., M, N) and whose innermost two dimensions form MxN matrices. Should have a floating-point data type.

  • rtol (Optional[Union[float, Tuple[float]]], default: None) – relative tolerance for small singular values. More details in ivy.pinv.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – An array containing the pseudo-inverses. More details in ivy.pinv.

Examples

>>> x = ivy.array([[1., 2.], [3., 4.]])
>>> y = x.pinv()
>>> print(y)
ivy.array([[-1.99999988,  1.        ],
       [ 1.5       , -0.5       ]])
>>> x = ivy.array([[1., 2.], [3., 4.]])
>>> z = ivy.zeros((2,2))
>>> x.pinv(rtol=0, out=z)
>>> print(z)
ivy.array([[-1.99999988,  1.        ],
       [ 1.5       , -0.5       ]])
Container.pinv(self, /, *, rtol=None, out=None)[source]#

ivy.Container instance method variant of ivy.pinv. This method simply wraps the function, and so the docstring for ivy.pinv also applies to this method with minimal changes.

Parameters:
  • x – input array having shape (..., M, N) and whose innermost two dimensions form``MxN`` matrices. Should have a floating-point data type.

  • rtol (Optional[Union[float, Tuple[float], Container]], default: None) – relative tolerance for small singular values approximately less than or equal to rtol * largest_singular_value are set to zero.

  • out (Optional[Container], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – an array containing the pseudo-inverses. The returned array must have a floating-point data type determined by type-promotion and must have shape (..., N, M) (i.e., must have the same shape as x, except the innermost two dimensions must be transposed).

Examples

>>> x = ivy.Container(a= ivy.array([[1., 2.], [3., 4.]]))
>>> y = x.pinv()
>>> print(y)
{
    a: ivy.array([[-1.99999988, 1.],
                  [1.5, -0.5]])
}
>>> x = ivy.Container(a = ivy.array([[1., 2.], [3., 4.]]))
>>> out = ivy.Container(a = ivy.zeros(x["a"].shape))
>>> x.pinv(out=out)
>>> print(out)
{
    a: ivy.array([[-1.99999988, 1.],
                  [1.5, -0.5]])
}