常量的四则运算
1 import tensorflow as tf 2 3 data1 = tf.constant(2) 4 data2 = tf.constant(10) 5 dataAdd=tf.add(data1,data2) 6 dataSub = tf.subtract(data1,data2) 7 dataMul = tf.multiply(data1,data2) 8 dataDiv = tf.divide(data1,data2) 9 10 with tf.Session() as sess: 11 12 print(sess.run(dataAdd)) 13 print(sess.run(dataSub)) 14 print(sess.run(dataMul)) 15 print(sess.run(dataDiv))
常量和变量的的四则运算
1 import tensorflow as tf 2 data1 = tf.constant(2) 3 data2 = tf.Variable(6) 4 dataAdd=tf.add(data1,data2) 5 dataSub = tf.subtract(data1,data2) 6 dataMul = tf.multiply(data1,data2) 7 dataDiv = tf.divide(data1,data2) 8 init = tf.global_variables_initializer() 9 with tf.Session() as sess: 10 sess.run(init) 11 print(sess.run(dataAdd)) 12 print(sess.run(dataSub)) 13 print(sess.run(dataMul)) 14 print(sess.run(dataDiv))