pynbody.util.rational_matrix_inv#
- pynbody.util.rational_matrix_inv(matrix)[source]#
A replacement for numpy linalg matrix inverse which handles fractions exactly.
Unlike numpy’s linalg package, this does not convert matrices to floats before inverting and is therefore completely accurate for fractional matrices.
However, it is only suitable for small matrices as otherwise it’s slow!
Based on public domain code by Jarno Elonen.
- Parameters:
matrix (array-like) – The matrix to invert
- Returns:
The inverted matrix
- Return type:
array-like