# discretize.utils.invert_blocks#

discretize.utils.invert_blocks(A)[source]#

Invert a set of 2x2 or 3x3 matricies.

This is a shortcut function that will only invert 2x2 and 3x3 matrices. The function is broadcast over the last two dimensions of A.

Parameters:
A(…, `N`, `N`) `numpy.ndarray`

the block of matrices to invert, N must be either 2 or 3.

Returns:
(…, `N`, `N`) `numpy.ndarray`

the block of inverted matrices

`numpy.linalg.inv`

Similar to this function, but is not specialized to 2x2 or 3x3

`inverse_2x2_block_diagonal`

use when each element of the blocks is separated

`inverse_3x3_block_diagonal`

use when each element of the blocks is separated

Examples

```>>> from discretize.utils import invert_blocks
>>> import numpy as np
>>> x = np.ones((1000, 3, 3))
>>> x[..., 1, 1] = 0
>>> x[..., 1, 2] = 0
>>> x[..., 2, 1] = 0
>>> As = np.einsum('...ij,...jk', x, x.transpose(0, 2, 1))
>>> Ainvs = invert_blocks(As)
>>> As[0] @ Ainvs[0]
array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])
```