您的位置:首页 > 理论基础

优达学城《计算机科学导论》 --判断反对称矩阵练习

2017-07-31 22:53 218 查看
# By Dimitris_GR from forums
# Modify Problem Set 31's (Optional) Symmetric Square to return True
# if the given square is antisymmetric and False otherwise.
# An nxn square is called antisymmetric if A[i][j]=-A[j][i]
# for each i=0,1,...,n-1 and for each j=0,1,...,n-1.

def antisymmetric(A):
for i in range(len(A)):
for j in range(len(A)):
if A[i][j]!=-1*A[j][i]:
return 'FALSE'
break
elif i==len(A)-1 and j==len(A)-1:
return 'TURE'
# Test Cases:
print antisymmetric([[0, 1, 2],
[-1, 0, 3],
[-2, -3, 0]])
#>>> True

print antisymmetric([[0, 1, 2],
[-1, 0, -2],
[2, 2,  3]])
#>>> False
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: