tensorflow中tensor的理解

import tensorflow as tf
a = tf.constant([1.0, 2.0], name = 'a')
b = tf.constant([2.0, 3.0], name = 'b')
result = tf.add(a, b, name = 'add')
print(result)

結果:Tensor(“add:0”, shape=(2,), dtype=float32)
張量表示的意思:Tensor(name名字,shape維度,type類型)
其中,名字的表示形式爲:node:src_output。node爲節點的名稱,src_output表示當前張量來自節點的第幾個輸出。add:0就表示,result這個張量是計算節點“add”輸出的第一個結果(編號從0開始)。
shape=(2,)表示張量result是一個一維數組,數組長度爲2.
dtype=float32表示類型。類型不匹配時會報錯。

如果想要得到具體的結果,必須要使用Session

with tf.Session() as sess:
    print(sess.run(result))

結果:[ 3. 5.]

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章