Tensorflow demo3 发表于 2017-02-28 参考极客学院基础教程 12345678910111213141516171819202122232425262728293031#coding:utf-8import tensorflow as tf# create two matrixesmatrix1 = tf.constant([[3,3], [2,2]]) #一行两列的数据matrix2 = tf.constant([[2,2], [2,3]]) # 一列两行的数据#matmul相乘product = tf.matmul(matrix1,matrix2)# method 1sess = tf.Session() #打开记得要关闭result = sess.run(product)#运行print resultsess.close()# [[12]] ==3*2+3*2 15 == 3*2+3*3 # method 2with tf.Session() as sess: #默认打开后关闭 result2 = sess.run(product) print result2 # [[12]][[12 15] [ 8 10]][[12 15] [ 8 10]]