备注: c是一个?*10的矩阵,c[x][i] * b[i] = z[x][i]
举例说明:
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
x = tf.reshape(tf.constant([1.0,2.0,3.0,4.0]),[2,2])
W = tf.reshape(tf.constant([1.0,2.0,3.0,4.0,5.0,6.0]), [2,3])
b = tf.reshape(tf.constant([1.0,2.0,3.0]),[1,3])
# 创建一个简单的神经网络
c = tf.matmul(x,W)
z = c + b
prediction = tf.nn.softmax(z)
with tf.Session() as sess:
print(sess.run([x,W,b,c,z,prediction]))
输出:
[array([[1., 2.],
[3., 4.]], dtype=float32),
array([[1., 2., 3.],
[4., 5., 6.]], dtype=float32),
array([[1., 2., 3.]], dtype=float32),
array([[ 9., 12., 15.],
[19., 26., 33.]], dtype=float32),
array([[10., 14., 18.],
[20., 28., 36.]], dtype=float32),
array([[3.29320406e-04, 1.79802869e-02, 9.81690347e-01],
[1.12497425e-07, 3.35350080e-04, 9.99664545e-01]], dtype=float32)]