for x in predRslt:
for y in actRslt:
if x == y and x =='1':
trueP += 1
elif x == y and x =='0':
trueN += 1
elif x != y and x == '1':
falseN += 1
elif x != y and x == '0':
falseP += 1
charNum += 1
totalActN = trueN + falseP
totalActP = falseN + trueP
totalPredN = trueN + falseN
totalPredP = trueP + falseP
print falseP
cmp_rslt('0110101001','1100100101')
实际输出:25
预期输出:2
im试图从一开始就遵循每个字符串,并比较结果。然后将相应的truen,truep,falsen或falsep递增。
出于某种原因,当我应该少的时间少时,我的输出不断达到25,因为只有10个比较我应该进行
您应该使用这样的第一个字符串的索引来迭代:
for idx, x in enumerate(predRslt);
y = actRslt[idx]
if x == y and x =='1':
trueP += 1
elif x == y and x =='0':
trueN += 1
elif x != y and x == '1':
falseN += 1
elif x != y and x == '0':
falseP += 1