import tensorflow as tf
c1 = tf.constant([[3,3]])
c2 = tf.constant([[3],[2]])
product = tf.matmul(c1 , c2)
with tf.Session() as sess:
reslut = sess.run(product)
print(reslut)
state = tf.Variable(0,name='counter')
#add
new_value = tf.add(state,1)
#update
# update = tf.assign(new_value , state)
update = tf.assign(state , new_value)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(state))
for _ in range(5):
print(sess.run(update))
print(sess.run(state))
0
1
2
3
4
5
5
#===============================
import tensorflow as tf
#fetch
c1 = tf.constant([3])
c2 = tf.constant([1])
c3 = tf.constant([6])
#add
add = tf.add(c1,c2)
mul = tf.multiply(c3,add)
with tf.Session() as sess:
print(sess.run([add,mul]))
21.0 7.0
#======================
#feed
c1 = tf.placeholder(tf.float32)
c2 = tf.placeholder(tf.float32)
add = tf.add(c1,c2)
with tf.Session() as sess:
print(sess.run(add,feed_dict={c1:[2],c2:[22]}))
#24.0