type 'tensorflow.python.framework.ops.EagerTensor' has no len()

Viewed 3451

I am trying to follow the TensorFlow tutorial on Windows: https://www.tensorflow.org/tutorials/eager/custom_training_walkthrough

Specifically I am having an issue with this section:

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

plt.xlabel("Petal length")
plt.ylabel("Sepal length");

Regarding the c = labels, the following error is returned: TypeError: object of type 'tensorflow.python.framework.ops.EagerTensor' has no len()

1 Answers

I have since determined that I need to convert to a numpy array as follows:

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

plt.xlabel("Petal length")
plt.ylabel("Sepal length");
Related