TensorFlow经典案例1:基本操作
import tensorflow as tf string = tf.constant("Hello World") with tf.Session() as sess: #在sess中运行op print(sess.run(string)) a = tf.constant(2) b = tf.constant(3) with tf.Session() as sess: print("a = 2 ,b = 3") print("计算a+b = %i" % sess.run(a+b)) print("计算a*b = %i" % sess.run(a*b)) a = tf.placeholder(tf.int16) b = tf.placeholder(tf.int16) add = tf.add(a,b) mul = tf.multiply(a,b) with tf.Session() as sess: print("计算a+b = %i" % sess.run(add,feed_dict={a:2,b:3})) print("计算a*b = %i" % sess.run(mul,feed_dict={a:2,b:3}))\ matrix1 = tf.constant([[3.,3.]]) matrix2 = tf.constant([[2.],[2.]]) product = tf.matmul(matrix1,matrix2) with tf.Session() as sess: result = sess.run(product) print(result)
公众号:一个有趣的机器学习社区
(大量机器学习资料分享)