tensorflow--session

矩阵相乘


import tensorflow as tf
import numpy as np
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# create two matrixes
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:
    result2 = sess.run(product)
    print(result2)

#numpy中的dot函数的矩阵相乘
matrix3 = np.mat([[3, 3]])
matrix4 = np.mat([[2],[2]])
result3 = np.dot(matrix3,matrix4)
print(result3)

你可能感兴趣的:(tensorflow--session)