Tensorflow的Hello和做加法運算

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()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章