小编sak*_*esh的帖子

TensorFlow TypeError:“BatchDataset”对象不可迭代/TypeError:“CacheDataset”对象不可下标

我正在遵循TensorFlow 入门指南。它特别表示要在鸢尾花(花)分类的示例项目上启用急切执行。

导入所需的 Python 模块(包括 TensorFlow),并启用该程序的即时执行。急切执行使 TensorFlow 立即评估操作,返回具体值,而不是创建稍后执行的计算图。如果您习惯了 REPL 或 python 交互式控制台,您将会有宾至如归的感觉。

因此,我按照说明启用急切执行,并继续执行说明。然而,当我到达讨论如何将数据集准备成张量流数据集的部分时,我遇到了错误。

细胞代码

train_dataset = tf.data.TextLineDataset(train_dataset_fp)
train_dataset = train_dataset.skip(1)             # skip the first header row
train_dataset = train_dataset.map(parse_csv)      # parse each row
train_dataset = train_dataset.shuffle(buffer_size=1000)  # randomize
train_dataset = train_dataset.batch(32)

# View a single example entry from a batch
features, label = iter(train_dataset).next()
print("example features:", features[0])
print("example label:", label[0])
Run Code Online (Sandbox Code Playgroud)

错误

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-61bfe99af85b> in <module>()

      7 
      8 # View a single example …
Run Code Online (Sandbox Code Playgroud)

python python-3.x tensorflow google-colaboratory

5
推荐指数
1
解决办法
1万
查看次数

TypeError:类型“numpy.int64”的对象没有 len() / TypeError:类型“int”的对象没有 len()/ 在 scikitlearn 中使用classification_report时

有时,当使用 sklearn.metrics.classification_report 时,我们会收到以下错误

TypeError: object of type 'int' has no len()
Run Code Online (Sandbox Code Playgroud)

有时根据数据类型,我们也会得到如下错误

TypeError: object of type 'numpy.int64' has no len()
Run Code Online (Sandbox Code Playgroud)

当我们可能收到此错误时的示例代码

t=pd.Series([1,2,3,4])
p=np.asarray([1,2,3,4])
target_names=[1,2,3,4]
print(classification_report(t, p, target_names=target_names))
Run Code Online (Sandbox Code Playgroud)

metrics python-3.x scikit-learn

5
推荐指数
1
解决办法
2690
查看次数

使用感叹号运行 bash 命令不适用于 python 提示符

我试图运行下面的命令但出现无效语法错误

$python
python 3.7.4
linux
>>> !ls
 File "<stdin>", line 1
   !ls
   ^
SyntaxError: invalid syntax
>>exit()
Run Code Online (Sandbox Code Playgroud)

python-3.x python-3.7

3
推荐指数
1
解决办法
3922
查看次数