session.run是运行session指针处代码
矩阵相乘例子
定义:
1 matrix1 = tf.constant([[3,3]]) 2 matrix2 = tf.constant([[2], 3 [2]]) 4 5 product = tf.matmul(matrix1,matrix2) #matrix multiply 6 7 #用numpy:numpy.dot(m1,m2)
执行:
1 #method 1 2 session = tf.Session() 3 result = sess.sun(product) 4 print(result) #[[12]] 5 sess.close()
1 #method 2 2 with tf.Session() as sess: 3 result2 = sess.run(product) #[[12]] 4 print(result2)