([ [3, 1], [4, 2]]) >>> A.inv_mod(3) Matrix([ [1, 1], [0, 1]]) Nz!Matrix is not invertible (mod %d)c