簡體   English   中英

TypeError:'float'對象在python 3中不是可迭代的錯誤

[英]TypeError: 'float' object is not iterable error in python 3

我正在使用 jupyter notebook python 3,並嘗試同時迭代支持向量回歸超參數的值,但出現以下錯誤。

見下圖:

類型錯誤:“浮動”對象不可迭代

您可能必須更改迭代變量才能與列表變量不同。 請像這樣改變。

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

此示例代碼重現了您的錯誤。

>>> 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM