tensorflow的placeholder学习
原型:
tf.placeholder(
dtype,
shape=None,
name=None
)
placeholder 是 Tensorflow 中的占位符,如果想要从外部传入data, 那就需要用到 tf.placeholder(),然后以这种形式传输数据 sess.run(***, feed_dict={input: **})传入数据。
placeholder 与 feed_dict={} 是绑定在一起出现的;这里没有变量,就不需要在上两个笔记的 init =tf.global_variables_initializer() 这一步了。
具体练习的代码:
import tensorflow as tf a1 = tf.placeholder(tf.float32) a2 = tf.placeholder(tf.float32) output = tf.multiply(a1,a2) with tf.Session() as sess: print(sess.run(output,feed_dict={a1:[3.],a2:[8.]}))
结果:[24.]