一、安裝
pip install tensorflow
二、簡介
tensor是張量的意思,flow是流動
張量是數據的載體,包括標量,向量,矩陣,數據立方,n維的數據
tensorflow的數據流圖,用節點和有向邊描述數學運算的有向無環圖,圖中節點代表操作,具體包括數學運算,數據填充,結果輸出和變量讀寫,有向邊描述了節點的輸入和輸出的關系,邊上流動這張量的數據。
1.節點分類
數學函數或表達式:MatMul、BiasAdd、Softmax
存儲模型參數的變量:ReLu Layer
占位符:Input Class Labels
梯度值
更新模型參數
2.有向邊
有向邊用於定義操作之間的關系,分為兩類,一類用來傳輸數據,另一類用來定義控制依賴
三、demo
import tensorflow as tf hello = tf.constant('hello ,tensorflow!') sess = tf.Session() print(sess.run(hello)) sp = tf.SparseTensor(indices=[[0,2],[1,3]],values=[1,2],dense_shape=[3,4]) x = tf.SparseTensor(indices = [[0,0],[0,2],[1,1]],values=[1,1,1],dense_shape=[2,3]) tf.sparse_reduce_sum(x,axis=1,keep_dims=True)
