python中求和用法_Python中的求和向量

嗨,我正在尝试在下面的输入示例中添加第3列:

输入1:act hi 1

act bye 2

act ciao 5

输入2:

^{pr2}$

具有以下所需输出:act-art hi 2

act-art bye 4

act-art kiss 5

act-art ciao 5

下面是我一直在使用的代码。在def sumVectors(classB_infile, classA_infile, outfile):

class_dictA = {}

with open(classA_infile, "rb") as opened_infile_A:

for line in opened_infile_A:

items = line.split()

classA, feat, valuesA = items[:3]

class_dictA[feat] = float(valuesA)

class_dictB = {}

with open(classB_infile, "rb") as opened_infile_B:

for line in opened_infile_B:

items = line.split()

classB, feat, valuesB = items[:3]

class_dictB[feat] = float(valuesB)

#print classA, classB, feat, sumVectors

####outfile

with open(outfile, "wb") as output_file:

for key in class_dictA:

if key in class_dictB:

weight = class_dictA[key] + class_dictB[key]

#outstring = "\t".join([classA + "-" + classB, key, str(weight)])

else:

weight = class_dictA[key]

outstring = "\t".join([classA + "-" + classB, key, str(weight)])

output_file.write(outstring + "\n")

for key in class_dictB:

if key in class_dictA:

weight = class_dictB[key]

outstring = "\t".join([classA + "-" + classB, key, str(weight)])

output_file.write(outstring + "\n")

但是,它给出了以下输出:act-art stress 5.0

act-art bye 2.0

act-art hi 1.0

act-art kiss 1.0

有没有什么见解可以解释为什么第二列中的值不求和?

谢谢你

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值