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))
从零开始 TensorFlow session进行符号运算
最新推荐文章于 2021-02-04 10:35:42 发布