在python张量流中打印生成器 [英] Printing a generator in python tensor flow
本文介绍了在python张量流中打印生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试按照tensor flow教程进行操作>链接
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
如何在python
中打印generator
.
我试图编写一个循环并遍历不起作用的元素,然后尝试使用next
打印生成器.那也没有用.如何打印?
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 ?
推荐答案
这就是我的解决方法
new_samples = np.array([test_data[8]], dtype=float)
y = list(classifier.predict(new_samples, as_iterable=True))
print('Predictions: {}'.format(str(y)))
print ("Predicted %s, Label: %d" % (str(y), test_labels[8]))
这篇关于在python张量流中打印生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文