Python:类型错误'float'对象不可迭代

问题描述 投票:0回答:1

我的代码是:

for ep in range(10):
    for x, y in tqdm(train_iterator.gen_batches(batch_size=64, 
                                           data_type="train")):
        x_embed = embedder(tokenizer(str_lower(x)))
        y_onehot = onehotter(classes_vocab(y))
        cls.train_on_batch(x_embed, y_onehot)

和结果:

<ipython-input-30-3f8c38399ce9> in <module>()
      2     for x, y in tqdm(train_iterator.gen_batches(batch_size=64, 
      3                                            data_type="train")):
----> 4         x_embed = embedder(tokenizer(str_lower(x)))
      5         y_onehot = onehotter(classes_vocab(y))
      6         cls.train_on_batch(x_embed, y_onehot)

1 frames
/usr/local/lib/python3.6/dist-packages/deeppavlov/models/preprocessors/str_lower.py in str_lower(batch)
     31         return batch.lower()
     32     else:
---> 33         return list(map(str_lower, batch))

TypeError: 'float' object is not iterable

我已经尝试将其更改为ep = int [float],但这也不起作用。

python for-loop floating-point iterable
1个回答
0
投票

str_lower()将字符串作为参数或可迭代类型,并在其上调用.lower()。但是,在您的代码中,x的类型为float。因此,每当以list()作为参数调用x时,都会返回此错误:

© www.soinside.com 2019 - 2024. All rights reserved.