user1420372
user1420372

Reputation: 2187

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

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

Upvotes: 4

Views: 3571

Answers (1)

user1420372
user1420372

Reputation: 2187

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");

Upvotes: 6

Related Questions