I am trying to follow the tensor flow
tutorial as described in this link
I am trying to print the predicted result as described :
print ("Predicted %d, Label: %d" % (classifier.predict(test_data[0]), test_labels[0]))
But I am not able to print the result. I am getting the following error.
print ("Predicted %d, Label: %d" % (classifier.predict(test_data[0]), test_labels[0]))
TypeError: %d format: a number is required, not generator
How do I print the generator
in python
.
I tried to write a loop and iterate over the elements it didn't work and I tried to use next
to print the generator. That also didn't work. How do I print it ?
This is how I solved it
No
tensorflow
here, so let's mock up a generator and test it against yourprint
expressionSo far, so good: I have the same problem that you've experienced.
The problem is, of course, that what you get when you call a generator function are not values but a generator object...
You have to iterate on the generator objects, using whatever is returned from each iteration, e.g.,
or, if you don't like one-liners,
In other words, you have to explicitly consume what the generator is producing.
From the documentation:
Try: