作者:放肆的微笑-扯痛了忧伤 | 来源:互联网 | 2023-09-07 19:29
Session的两种使用方式,以矩阵相乘为例。方式1importtensorflowastfmatrix1tf.constant([[3,3]])matrix2
Session的两种使用方式,以矩阵相乘为例。
方式1
import tensorflow as tf
matrix1 = tf.constant([[3, 3]])
matrix2 = tf.constant([[2], [2]])
product = tf.matmul(matrix1, matrix2)
sess = tf.Session()
result = sess.run(product)
print(result)
sess.close()
方式2
import tensorflow as tf
matrix1 = tf.constant([[3, 3]])
matrix2 = tf.constant([[2], [2]])
product = tf.matmul(matrix1, matrix2)
with tf.Session() as sess:
result = sess.run(product)
print(result)