問題
tensor詳細數值 不能直接print打?。?/p>
import tensorflow as tfx = tf.constant(1)print x
輸出:
Tensor("Const:0", shape=(), dtype=int32)
原因:
print只能打印輸出shape的信息,而要打印輸出tensor的值,需要借助 tf.Session,tf.InteractiveSession。
因為我們在建立graph的時候,只建立 tensor 的 結構形狀信息 ,并沒有 執行 數據的操作。
解決方法
法一:
import tensorflow as tfx = tf.constant(1)with tf.Session() as sess: print sess.run(x)
輸出:
1
法二:
import tensorflow as tfx = tf.constant(1)sess = tf.InteractiveSession()print x.eval()
輸出:
1
以上這篇tensorflow: 查看 tensor詳細數值方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答