109、TensorFlow計算張量的值


# 當計算圖創建成功時
# 你就可以運行這個計算圖,然后生成一個新的張量
# 並且得到這個張量指向的計算圖中具體的數值
#這個功能在debug的時候非常有必要
#最簡單獲得張量具體值的方法是使用Tensor.eval method
import tensorflow as tf
constant = tf.constant([1, 2, 3])
#進行點乘,對應位置的元素相乘
tensor = constant * constant
init = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init)
    #eval方法只有當session開啟的時候才好用
    #Tensor.eval 方法返回一個python的numpy對象,和原來的張量有着相同的值
    print(tensor.eval())

下面是上面輸出的張量的結果:

2018-02-16 21:46:48.085119: I C:\tf_jenkins\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
[1 4 9]

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM