TensorFlow不输出结果

img


同学和我同样的安装方式,a+b直接输出可以输出[3 7],而我输出的是add_25:0,并且这个值每运行一次都会增加。上图是用了sess.run才输出结果。想知道这是为什么?有什么解决方法

基于Monster 组和GPT的调写:
指定要使用的图形并获得 a+b 的正确输出:

import tensorflow as tf

# 创建新图形
graph = tf.Graph()

# 将图形设置为默认图形
with graph.as_default():
    a = tf.constant([1,3])
    b = tf.constant([2,4])
    c = tf.add(a, b)

# 创建会话并使用新图形
with tf.compat.v1.Session(graph=graph) as sess:
    print(sess.run(c))