因此,我已两个不同的2维阵列words
和scores
蟒:在类型错误上元组结果的算术操作
words
是串 scores
的2维数组是浮体的2维阵列
我将它们转换为元组并对它们执行算术运算(我最初将元组传递给库,但为了简单起见,我复制了操作并开始测试它)
我的代码
for i in range(0,len(scores)):
freqs = []
for word, score in zip(words[i], scores[i]):
freqs.append((word, score))
frequencies = [ (word, freq/20.0) for word, freq in freqs ]
当我运行这段代码,我得到以下错误
TypeError Traceback (most recent call last)
<ipython-input-17-017692219adb> in <module>()
4 for word, score in zip(words[i], scores[i]):
5 freqs.append((word, score))
----> 6 frequencies = [ (word, freq/20.0) for word, freq in freqs ]
7
8 #elements = wc.fit_words(freqs)
TypeError: unsupported operand type(s) for /: 'str' and 'float'
你确定'freq'(在你的综合列表中)包含数字而不是字符串吗? – Daneel