占位符 tf.placeholder()
用两个输入的占位符:矩阵x和向量w。这些输入是矩阵相乘以创建一个5个元素的向量xw,并加上一个填充了值为-1的常数向量b。最后,变量s通过使用tf.reduce_max()操作获取该向量的最大值。使用单词reduce是因为我们将一个5个元素的向量化归到一个标量。
例如:
import tensorflow as tf
import numpy as np
x_data = np.random.randn(5,10)
w_data = np.random.randn(10,1)
with tf.Graph().as_default():
x = tf.placeholder(tf.float32,shape=(5,10))
w = tf.placeholder(tf.float32,shape=(10,1))
b = tf.fill((5,1),-1.)
xw = tf.matmul(x,w)
xwb = xw +b
s = tf.reduce_max(xwb)
with tf.Session() as sess:
outs = sess.run(s,feed_dict={x:x_data,w:w_data})
print('outs = {}'.format(outs))