标签:false png img session 技术 value pre flow name
首先,激活tensorflow环境( source activate tensorflow ),随后
1 import tensorflow as tf 2 sess = tf.Session()
创建标量(scalar)或张量(tensor)形式的常量
1 tf.constant(value, dtype=None, shape=None, name=‘Const‘, verify_shape=False)
例1:
1 node1 = tf.constant(3.0, dtype=tf.float32) 2 node2 = tf.constant(4.0) 3 print(sess.run([node1, node2]))
输出:
[3.0, 4.0]
例2:
1 a = tf.constant([2, 2], name="vector") 2 print(sess.run(a))
输出:
[2 2]
拓展:
1 a = tf.constant([3, 6]) 2 b = tf.constant([2, 2]) 3 tf.add(a, b) # >> [5 8] 4 tf.add_n([a, b, b]) # >> [7 10]. Equivalent to a + b + b 5 tf.mul(a, b) # >> [6 12] because mul is element wise 6 tf.matmul(a, b) # >> ValueError 7 tf.matmul(tf.reshape(a, shape=[1, 2]), tf.reshape(b, shape=[2, 1])) # >> [[18]] 8 tf.div(a, b) # >> [1 3] 9 tf.mod(a, b) # >> [1 0]
标签:false png img session 技术 value pre flow name
原文地址:http://www.cnblogs.com/CongYuUestcer/p/7367439.html