# tensorflow基础语法
# 导入tensorflow
import tensorflow as tf
# 屏蔽线性运算的警告
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
def add_demo():
"""
使用tensorflow来完成加法运算
:return:
"""
# 定义两个张量
tensor_a = tf.constant(10)
tensor_b = tf.constant(20)
# 计算两个张量的和
"""
tensor_a : Tensor("Const:0", shape=(), dtype=int32)
sum_c : Tensor("Add:0", shape=(), dtype=int32)
"""
# sum_c = tensor_a + tensor_b
sum_c = tf.add(tensor_a, tensor_b)
print("tensor_a :", tensor_a)
print("sum_c :", sum_c)
# 所有tensorflow程序中,如果想要访问张量内部的值,必须要开启会话
with tf.Session() as sess:
print("tensor_a = ", sess.run(tensor_a))
print("sum_c = ", sess.run(sum_c))
return None
"""
tensorflow 里面的结构分析:
1. 图
2. 会话
3. 张量
4. 节点
"""
add_demo()
02-19
887
09-12
2307
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交