基本概念
基本结构
创建图和启动图,常量使用
import tensorflow as tf
# 创建 op 常量
m1 = tf.constant([[3,3]])
m2 = tf.constant([[2],[3]])
product = tf.matmul(m1, m2)
print(product)
# Tensor("MatMul:0", shape=(1, 1), dtype=int32)
# 自定义一个会话, 使用默认图
sess = tf.Session()
# 调用 sess 的 run 方法来执行矩阵乘法 op
# run(product) 触发了 3 个 op
result = sess.run(product)
print(result)
# [[15]]
sess.close()
# 自动关闭
with tf.Session() as sess:
result = sess.run(product)
print(result)
# [[15]]
变量
import tensorflow as tf
x = tf.Variable([1,2])
a = tf.constant([3,3])
#