1.Tensorflow的使用:先羅列,后操作
2.賦值不能使用=,要使用賦值op
3.使用到變量,需要執行初始化op
4.print(op)的結果是張量:
? ? <tf.Variable 'Variable:0' shape=() dtype=int32_ref>
5.print(sess.run(op))的結果是值:7
6.如果op是變量,打印它的值也需要在會話中執行:
? ? ? print(tf.run(變量))
常量:
直接給出每行每列的數據,但不可改變
1.a = tf.constant( [ [1,2,4] , [4,5,6] ] )//2行3列的常量
2.x= tf.constant(tf.random_normal([1,10]))//1行10列隨機數生成函數來初始化
3.x= tf.constant(tf.zeros([1,10]))//1行10列常數生成函數來初始化
4.initial = tf.constant(0.1,shape=shape)
變量:
直接給出每行每列的數據,但可以改變
1.x= tf.Variable([1,2])
2.x= tf.Variable(tf.random_normal([1,10]))//1行10列隨機數生成函數來初始化
3.x= tf.Variable(tf.zeros([1,10]))//1行10列常數生成函數來初始化
占位符:
只能定義形狀,通過FEED賦值
x = tf.placeholder(tf.float32,[None,1])
sess.run(train_step,feed_dict={x: x_data})
生成函數:
只能定義形狀,結果是值,可以給變量和常量
tf.random_normal([1,10])