def Gauss_elimination(A): R = A.copy() #Result m, n = len(R), len(R[0]) #Size of matrix row = col = 0 while row < m: #Step 1: Determines the leftmost column that does not contain all zeroes while col < n and all(isZero(R[i][col]) for i in range(row, m)): col += 1 if col == n: #Echelon matrix break #Step 2: Select the first line with a non-zero term. Switch two rows pivot_row = row + [not isZero(R[i][col]) for i in range(row, m)].index(True) switchRow(R, row, pivot_row) #Step 3: With the leading term from Step 2 being a≠0 , multiply the row containing it by 1/a mulRow(R, row, 1/R[row][col]) #Step 4: Add an appropriate multiple of the top line to each bottom line to turn the terms below the leading number into 0 for i in range(row + 1, m): multiplier = R[i][col] / R[row][col] addRow(R, i, row, -multiplier) #Step 5: Repeat the steps until you get the echolon matrix. row += 1 printMatrix(R) print("\n") return R