TensorFlow 编程训练2

xiaoxiao2021-02-28  39

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)
转载请注明原文地址: https://www.6miu.com/read-1950302.html

最新回复(0)