從零開始 TensorFlow session進行符號運算
阿新 • • 發佈:2018-12-24
from __function__ import print_function
import tensorflow as tf
a=tf.constant(2)
b=tf.constant(3)
with tf.Session() as sess:
print('sess run ... a+b result: %i' % sess.run(a+b))
print('sess run ... a*b result: %i' % sess.run(a*b))
a = tf.placeholder(tf.int16)
b = tf.placeholder(tf.int16)
add= tf.add(a,b)
multi=tf.multiply(a,b)
with tf.Session() as sess:
print('sess run ... add result: %i' % sess.run(add,feed_dict={a:2,b:3}))
print('sess run ... multi result: %i' % sess.run(multi,feed_dict={a:2,b:3}))
a=tf.constant([[2,3]])
b=tf.constant([[3],[1]])
re=tf.matmul(a,b)
with tf.Session() as sess:
print('matrix multi result:',sess.run(re))