import tensorflow as tf
c1 = tf.constant([[3,3]])
c2 = tf.constant([[3],[2]])
product = tf.matmul(c1 , c2)
print(product)
输出结果 Tensor("MatMul_1:0", shape=(1, 1), dtype=int32)
sess = tf.Session()
reslut = sess.run(product)
print(reslut)
输出结果 [[15]]
#定义会话,在会话中执行语句
with tf.Session() as sess:
reslut = sess.run(product)
print(reslut)
输出结果 [[15]]
x = tf.Variable([1,2])
c = tf.constant([3,3])
#减法op
sub = tf.subtract(x,c)
#加法op
add = tf.add(x,c)
#变量初始化
init = tf.global_variables_initializer() #创建session 并创建默认图
with tf.Session() as sess:
sess.run(init)
print(sess.run(sub))
print(sess.run(add))
输出结果 [-2 -1] [4 5]