权值和偏置值
- x = tf.placeholder(tf.float32,[None,784]) # 输入一个矩阵 ?*784
- W = tf.Variable(tf.zeros([784,10])) # 是一个784*10的矩阵
- b = tf.Variable(tf.zeros([10])) # 是一个1*10的矩阵
- c = tf.matmul(x,W)
- z = c + b
- prediction = tf.nn.softmax(z) # 使用softmax做激活函数
备注: 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,