for i in range(n): if i!=c and Mx[i][c]!=0: z=Mx[i][c] Mx[i]=[Mx[i][j]-z*Mx[c][j] for j in range(n*2)] return [row[n:] for row in Mx] inv=inv2