以下代码不会出现任何错误,但也不会打印张量。
import tensorflow as tf
import numpy as np
# Some tensor we want to print the value of
x = tf.placeholder(tf.float32, shape=[2, 2, 2])
a = np.array([[[1.,1.], [1.,1.]], [[2.,2.], [2.,2.]]])
m = tf.Print(x,[x])
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
m_eval = m.eval(session=sess,feed_dict={x: a})
编辑:在bgshi的回复之后,我发现在iPython控制台中,代码会打印张量值。但我正在使用iPython笔记本。有没有办法让它显示在笔记本上?