tensorflow中placeholder的用法
import tensorflow as tf
imort numpy as np
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32) #为输入input1和input2预留空间,此处也可以指定shape,见下面的例子
output = tf.multiply(input1,input2) # 教程中使用的是mul
with tf.Session() as session:
print(session.run(output,feed_dict={input1:[7.],input2:[2.]})) #输出结果为[14.]
input3 = tf.placeholder(tf.float32,[1,3])
input4 = tf.placeholder(tf.float32,[1,3]) #输入的是1行3列的数组
output = tf.multiply(input3,input4) #对应位分别相乘
with tf.Session() as session:
print(session.run(output,feed_dict={input3:np.array([1,2,3]),input4:np.array([1,2,3])})) # 将array([1,2,3])分别赋值给input3,input4 ,输出结果为[[1.,4.,9.]]