今天刚刚完成了tensorflow的安装,想要立刻试一下是否可以使用
网上有这么一段程序,我拿来跑了一下
import tensorflow as tf v_1=tf.constant([1,2,3,4]) v_2=tf.constant([2,3,4,5]) v_add=tf.add(v_1,v_2) sess=tf.compat.v1.Session() print(sess.run(v_add))
这个程序跑的时候会报错
后来加上
tf.compat.v1.disable_eager_execution()
就可以了,如图:
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
v_1=tf.constant([1,2,3,4])
v_2=tf.constant([2,3,4,5])
v_add=tf.add(v_1,v_2)
sess=tf.compat.v1.Session()
print(sess.run(v_add))