TensorFlow基础2——session两种开启方式

session两种开启方式

 1 import tensorflow as tf 
 2 
 3 martix1 = tf.constant([[3,3]])
 4 martix2 = tf.constant([[2],[2]])
 5 
 6 product = tf.matmul(martix1,martix2)
 7 
 8 #method 1
 9 sess = tf.Session()
10 result = sess.run(product)
11 print(result)
12 sess.close()
13 
14 #method 2
15 with tf.Session() as sess:
16     result2 = sess.run(product)
17     print(result2)

 

posted @ 2017-08-11 09:42  超任  阅读(2037)  评论(0编辑  收藏  举报