Tensorflow session

来源:互联网 发布:顶尖硬盘数据恢复软件 编辑:程序博客网 时间:2024/06/03 18:39

传送门
Tensorflow定义完图结构,并不会直接计算,需要利用session才能激活。一般直接利用第一种session机制就足够了。

# View more python learning tutorial on my Youtube and Youku channel!!!# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg# Youku video tutorial: http://i.youku.com/pythontutorial"""Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly."""from __future__ import print_functionimport tensorflow as tfmatrix1 = tf.constant([[3, 3]])matrix2 = tf.constant([[2],                       [2]])product = tf.matmul(matrix1, matrix2)  # matrix multiply np.dot(m1, m2)# method 1sess = tf.Session()result = sess.run(product)print(result)sess.close()# method 2with tf.Session() as sess:    result2 = sess.run(product)    print(result2)
0 0
原创粉丝点击