模块TensorFlow中没有Session
AttributeError: module ‘tensorflow’ has no attribute ‘Session’
提示:TensorFlow中没有模块Session;
原因是:我们引用的TensorFlow2.0版本,此版本与1.0相比没有模块Session。
解决方法:
以之前抄的一段代码为例:
import tensorflow as tf
data1 = tf.constant([[6,6]])
data2 = tf.constant([[2]
,[2]])
data3 = tf.constant([3,3])
data4 = tf.constant([[1,2],
[3,4],
[5,6]])
#print(data4.shape)
#print(data1)
with tf.Session() as sess:
print(sess.run(data1[0])) #打印一行
print(sess.run(data4))
print(sess.run(data4[:,0])) #打印第零列
print(sess.run(data4[0,1]))
print(sess.run(data4[0])) #打印第O行
</