Skip to content

Instantly share code, notes, and snippets.

@j9ac9k
j9ac9k / gauss.py
Last active July 9, 2023 01:52
Gaussian Elimination in Python
def gauss(A):
m = len(A)
assert all([len(row) == m + 1 for row in A[1:]]), "Matrix rows have non-uniform length"
n = m + 1
for k in range(m):
pivots = [abs(A[i][k]) for i in range(k, m)]
i_max = pivots.index(max(pivots)) + k
# Check for singular matrix