import numpy as np
def triangleFun(a,b):
row=a.shape[0]
col=a.shape[1]
n=row-1
for i in range(0,n):
for j in range(i+1,n): #变为上对角元素
lam =float(a[j,i])/a[i,i]
a[j,0:n]=a[j,0:n]-lam*a[i,0:n]
b[j,0:n]=b[j,0:n]-lam*a[i,0:n]
for p in range(n,-1,-1):
for q in range(p-1,-1,-1): #变为下对角元素
lam=float(a[q,p])/a[p,p]
a[q,::-1]=a[q,::-1]-lam*a[p,::-1]
b[q,::-1]=b[q,::-1]-lam*a[p,::-1]
for l in range(0,n+1):
a[l,l]=a[l,l]/a[l,l]
b[l,:]=b[l,:]/a[l,l]
print(a,b)
a =np.mat([[1,2,1,4],[2,0,4,3],[4,2,2,1],[-3,1,3,2]])
b=np.eye(4)
print(triangleFun(a,b))