tensorflow学习笔记

时间:2021-07-17 05:28:26

常量的四则运算

 import tensorflow as tf

 data1 = tf.constant(2)
data2 = tf.constant(10)
dataAdd=tf.add(data1,data2)
dataSub = tf.subtract(data1,data2)
dataMul = tf.multiply(data1,data2)
dataDiv = tf.divide(data1,data2)
with tf.Session() as sess:
print(sess.run(dataAdd))
print(sess.run(dataSub))
print(sess.run(dataMul))
print(sess.run(dataDiv))

常量和变量的的四则运算

 import tensorflow as tf
data1 = tf.constant(2)
data2 = tf.Variable(6)
dataAdd=tf.add(data1,data2)
dataSub = tf.subtract(data1,data2)
dataMul = tf.multiply(data1,data2)
dataDiv = tf.divide(data1,data2)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(dataAdd))
print(sess.run(dataSub))
print(sess.run(dataMul))
print(sess.run(dataDiv))