Python: easy, efficient way to check if determinant is 0 (mod large prime)?

75 views Asked by At

I want to check if an nxn matrix has 0 determinant. I don't care what the exact value is, just whether or not it is 0. The entries may be large integers, so I was thinking of doing Gaussian elimination mod a large prime p to limit the size of computations (I'm aware this makes the alg not exact). Doing this from scratch seems annoying, though; it seems like there must be something out there that has done this already, but I can't find it in the typical places like numpy libraries. Does anyone know of an existing solution?

1

There are 1 answers

0
Richard On

Use Numpy

import numpy as np
matrix = [[1, 2], [4, 8]]
print(np.linalg.det(matrix) == 0)

See https://numpy.org/doc/stable/reference/generated/numpy.linalg.det.html

I am not aware of specifically 0 check though