Hexo

Tensorflow demo3

参考极客学院基础教程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#coding:utf-8
import tensorflow as tf
# create two matrixes
matrix1 = tf.constant([[3,3],
[2,2]]) #一行两列的数据
matrix2 = tf.constant([[2,2],
[2,3]]) # 一列两行的数据
#matmul相乘
product = tf.matmul(matrix1,matrix2)
# method 1
sess = tf.Session() #打开记得要关闭
result = sess.run(product)#运行
print result
sess.close()
# [[12]] ==3*2+3*2 15 == 3*2+3*3
# method 2
with tf.Session() as sess: #默认打开后关闭
result2 = sess.run(product)
print result2
# [[12]]
[[12 15]
[ 8 10]]
[[12 15]
[ 8 10]]