1. 程式人生 > >TensorFlow矩陣乘法-認識Session

TensorFlow矩陣乘法-認識Session

tensorflow教程順序有點亂,其實這個應該放在第一篇的,大夥湊合看吧^_^

硬體:NVIDIA-GTX1080

軟體:Windows7、python3.6.5、tensorflow-gpu-1.4.0

一、基礎知識

矩陣乘法規則:1x2的matrix和2x1的matrix相乘,得到1x1的matrix

二、程式碼展示

import tensorflow as tf

matrix1 = tf.constant([[3,3]])
matrix2 = tf.constant([[2],
                       [2]])
product = tf.matmul(matrix1, matrix2)

##method 1
#sess = tf.Session()
#result = sess.run(product)
#print(result)
#sess.close()

#method 2
with tf.Session() as sess:
    result = sess.run(product)
    print(result)

三、執行結果

[[12]]

 

任何問題請加唯一QQ2258205918(名稱samylee)!