# inv#

Return the multiplicative inverse of a square matrix (or a stack of square matrices) `x`.

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

• 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 multiplicative inverses. The returned array must have a floating-point data type determined by type-promotion and must have the same shape as `x`.

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

With `ivy.Array` inputs:

```>>> x = ivy.array([[1.0, 2.0], [3.0, 4.0]])
>>> y = ivy.zeros((2, 2))
>>> ivy.inv(x, out=y)
>>> print(y)
ivy.array([[-2., 1.],[1.5, -0.5]])
```
```>>> x = ivy.array([[1.0, 2.0], [5.0, 5.0]])
>>> ivy.inv(x, out=x)
>>> print(x)
ivy.array([[-1., 0.4],[1., -0.2]])
```
```>>> x = ivy.array([[[1.0, 2.0],[3.0, 4.0]],
...                [[1.0, 3.0], [3.0, 5.0]]])
>>> y = ivy.inv(x)
>>> print(y)
ivy.array([[[-2., 1.],[1.5, -0.5]],
[[-1.25, 0.75],[0.75, -0.25]]])
```

With `ivy.Container` inputs

```>>> x = ivy.Container(a=ivy.array([[11., 100., 10.],
...                                [300., 40., 20.], [25., 30, 100.]]),
...                   b=ivy.array([[4., 400., 50.], [10., 10., 15.],
...                               [50., 5000., 40.]]),
...                   c=ivy.array([[25., 22., 100.], [55, 20., 20.],
...                               [55., 50., 100.]]))
>>> y = x.inv()
>>> print(y)
{
a: ivy.array([[-0.0012, 0.00342, -0.000565],
[0.0104, -0.0003, -0.000981],
[-0.00282, -0.000766, 0.0104]]),
b: ivy.array([[-0.0322, 0.101, 0.00237],
[0.000151, -0.00101, 0.00019],
[0.0214, 0., -0.00171]]),
c: ivy.array([[0.0107, 0.03, -0.0167],
[-0.0472, -0.0322, 0.0536],
[0.0177, -0.000429, -0.00762]])
```

}

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

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

• 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 multiplicative inverses. The returned array must have a floating-point data type determined by type-promotion and must have the same shape as `x`.

Examples

With `ivy.Array` inputs:

```>>> x = ivy.array([[1.0, 2.0],[3.0, 4.0]])
>>> y = x.inv()
>>> print(y)
ivy.array([[-2., 1.],[1.5, -0.5]])
```
Container.inv(self, /, *, adjoint=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
• self (`Container`) – Ivy container having shape `(..., M, M)` and whose innermost two dimensions form square matrices. Should have a floating-point data type.

• key_chains (`Optional`[`Union`[`List`[`str`], `Dict`[`str`, `str`], `Container`]], default: `None`) – The key-chains to apply or not apply the method to. Default is `None`.

• to_apply (`Union`[`bool`, `Container`], default: `True`) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is `True`.

• prune_unapplied (`Union`[`bool`, `Container`], default: `False`) – Whether to prune key_chains for which the function was not applied. Default is `False`.

• map_sequences (`Union`[`bool`, `Container`], default: `False`) – Whether to also map method to sequences (lists, tuples). Default is `False`.

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

Return type:

`Container`

Returns:

ret – A container containing the multiplicative inverses. The returned array must have a floating-point data type determined by type-promotion and must have the same shape as `x`.

Examples

With `ivy.Container` input:

```>>> x = ivy.Container(a=ivy.array([[0., 1.], [4., 4.]]),
...                      b=ivy.array([[4., 4.], [2., 1.]]))
>>> y = x.inv()
>>> print(y)
{
a: ivy.array([[-1, 0.25], [1., 0.]]),
b: ivy.array([-0.25, 1.], [0.5, -1.])
}
```