TypeError:“ float”对象在python 3中不是可迭代错误

时间:2019-11-24 06:16:12

标签: python regression svm

我正在使用jupyter笔记本python 3,并尝试同时迭代支持向量回归超参数的值,但出现以下错误。

请参见下图:

TypeError: 'float' object is not iterable

2 个答案:

答案 0 :(得分:2)

您可能必须更改迭代变量才能与列表变量不同。 请这样更改。

for i in C:
    for j in e:
        ...

答案 1 :(得分:1)

此示例代码再现了您的错误。

>>> l = [1,2,3]
>>> m = [5,6,7]
>>> for l in l:
        for m in m:
            print(l,m)


1 5
1 6
1 7
Traceback (most recent call last):
  File "<pyshell#11>", line 2, in <module>
    for m in m:
TypeError: 'int' object is not iterable

您必须像这样更改迭代器变量名称。

>>> l = [1,2,3]
>>> m = [5,6,7]
>>> for l_i in l:
        for m_i in m:
            print(l_i,m_i)


1 5
1 6
1 7
2 5
2 6
2 7
3 5
3 6
3 7