类型 'tensorflow.python.framework.ops.EagerTensor' 没有 len()

use*_*372 4 python tensorflow

我正在尝试遵循 Windows 上的 TensorFlow 教程:https : //www.tensorflow.org/tutorials/eager/custom_training_walkthrough

具体来说,我对此部分有疑问:

plt.scatter(features['petal_length'],
            features['sepal_length'],
            c=labels,
            cmap='viridis')

plt.xlabel("Petal length")
plt.ylabel("Sepal length");
Run Code Online (Sandbox Code Playgroud)

关于 c = 标签,返回以下错误:TypeError: object of type 'tensorflow.python.framework.ops.EagerTensor' has no len()

use*_*372 6

我已经确定我需要转换为一个 numpy 数组,如下所示:

plt.scatter(features['petal_length'],
            features['sepal_length'],
            c=labels.numpy(),
            cmap='viridis')

plt.xlabel("Petal length")
plt.ylabel("Sepal length");
Run Code Online (Sandbox Code Playgroud)