d = np.array([
[4,1,2,4],
[1,2,0,2],
[10,5,2,0],
[0,1,1,7]
])
print(d)
np.linalg.det(d) # 计算行列式结果
[[ 4 1 2 4] [ 1 2 0 2] [10 5 2 0] [ 0 1 1 7]]
Out[4]:
-8.511709855459539e-15
def createD(a,x,n):
# 构建函数,生成一个n阶的行列式,其中对角线值为x,其余为a
di = np.eye(n)
di = di * x
di[di==0] = a
return di
d = createD(5,20,10)
print(d)
np.linalg.det(d)
[[20. 5. 5. 5. 5. 5. 5. 5. 5. 5.] [ 5. 20. 5. 5. 5. 5. 5. 5. 5. 5.] [ 5. 5. 20. 5. 5. 5. 5. 5. 5. 5.] [ 5. 5. 5. 20. 5. 5. 5. 5. 5. 5.] [ 5. 5. 5. 5. 20. 5. 5. 5. 5. 5.] [ 5. 5. 5. 5. 5. 20. 5. 5. 5. 5.] [ 5. 5. 5. 5. 5. 5. 20. 5. 5. 5.] [ 5. 5. 5. 5. 5. 5. 5. 20. 5. 5.] [ 5. 5. 5. 5. 5. 5. 5. 5. 20. 5.] [ 5. 5. 5. 5. 5. 5. 5. 5. 5. 20.]]
Out[20]:
2498818359374.998