import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 忽略警告
msg = tf.constant("hello Tensor Flow!")
with tf.compat.v1.Session() as sess:
print(sess.run(msg).decode())
sess.close() # 创建一个with对话 在对应的结束建议关闭对话
# 做加法运算
v1 = tf.constant([1, 2, 3, 4])
v2 = tf.constant([4, 3, 2, 1])
ret = tf.add(v1, v2)
# 做除法运算
d1 = tf.constant(1)
d2 = tf.constant(3)
res = tf.divide(d1, d2)
with tf.compat.v1.Session() as sess:
print(sess.run(v1))
print(sess.run(v2))
print(sess.run(ret))
print(sess.run(res))
sess.close()