新手学tensorflow,tf.constant用法

import tensorflow as tf
import numpy as np

x = np.array([[1, 4, 3], #将list转换为array
              [1, 6, 3],
              [1, 2, 3]])

#将array转换为tf.constant
x1 = tf.constant(value=x, dtype=tf.float32, shape=[3, 3])

y = np.array([[1, 2],
              [2, 3],
              [4, 5]])
x2 = tf.constant(value=y, dtype=tf.float32, shape=[3, 2])
'''
x1 = tf.constant([[1, 2, 3],
                  [1, 2, 3],
                  [1, 2, 3]])
x2 = tf.constant([[1, 2],
                  [2, 3],
                  [4, 5]])
'''

z = tf.matmul(x1, x2)  #矩阵乘法
with tf.Session() as sess:
    print(sess.run(z))

猜你喜欢

转载自blog.csdn.net/z2539329562/article/details/79842186