一、常量之间的四则运算
import tensorflow as tf
data1 = tf.constant(6)
data2 = tf.constant(2)
Add = tf.add(data1, data2)
Mul = tf.multiply(daat1, data2)
Sub = tf.subtract(data1, data2)
Div = tf.divide(data1, data2)
with tf.Session() as sess:
print(sess.run(Add))
print(sess.run(Mul))
print(sess.run(Sub))
print(sess.run(Div))
二、常量和变量之间的运算
data1= tf.constant(6)
data2 = tf.Variable(2)
Add = tf.add(add1, add2)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(Add))
网友评论