我知道我的代码有误,因为np.sum(abs(X),axis=1))也会将对角线的值加起来,因此我的代码总是返回“NOT diagonally dominant”。我尝试使用“-np.diag(X)”,但出现错误消息。提前感谢您的帮助!
import numpy as np
A=np.array([[ 40., 7., 5.],
[ 5., 90., 7.],
[20., 7., 50.]])
def dd(X):
Sum_values_in_given_row = np.sum(abs(X),axis=1)
if np.all(((abs(np.diag(X)))) >= np.sum(abs(X),axis=1)):
print 'matrix is diagonally dominant'
else:
print 'NOT diagonally dominant'
return
dd(A)