0
我很確定表示矩陣的1-0矩陣是可傳遞的a_ij = 1 == a_ji = 1意味着a_ii == 1對於矩陣a (不知道雖然)。問題是我總是迴歸真實。謝謝你的幫助。確定代表關係的1-0矩陣是否是可傳遞的
def transitive(a):
"""Returns True if the relation M is transitive, False otherwise."""
assert (len(row) == len(M) for row in M)
for i in range (len(a)):
for j in range (len(a)):
if (a[i][j] == 1 and a[j][i] == 1 and a[i][i] == 1):
return True
return False
print transitive([[1,0,1],[0,1,1],[0,1,1]])