xw+b

# 测试xw+b
import tensorflow as tf

x = tf.Variable(tf.constant(3.0, shape=[5, 5]))
w = tf.Variable(tf.constant(4.0, shape=[5, 8]))
b = tf.Variable(tf.constant(5.0, shape=[8]))
h = tf.add(tf.matmul(x, w), b)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(x.eval())
    print(w.eval())
    print(b.eval())
    print(h.eval())
# [[3. 3. 3. 3. 3.]
#  [3. 3. 3. 3. 3.]
#  [3. 3. 3. 3. 3.]
#  [3. 3. 3. 3. 3.]
#  [3. 3. 3. 3. 3.]]
# [[4. 4. 4. 4. 4. 4. 4. 4.]
#  [4. 4. 4. 4. 4. 4. 4. 4.]
#  [4. 4. 4. 4. 4. 4. 4. 4.]
#  [4. 4. 4. 4. 4. 4. 4. 4.]
#  [4. 4. 4. 4. 4. 4. 4. 4.]]
# [5. 5. 5. 5. 5. 5. 5. 5.]
# [[65. 65. 65. 65. 65. 65. 65. 65.]
#  [65. 65. 65. 65. 65. 65. 65. 65.]
#  [65. 65. 65. 65. 65. 65. 65. 65.]
#  [65. 65. 65. 65. 65. 65. 65. 65.]
#  [65. 65. 65. 65. 65. 65. 65. 65.]]

猜你喜欢

转载自blog.csdn.net/xky1306102chenhong/article/details/81138264