tensorflow的placeholder学习

原型:spa

tf.placeholder(
    dtype,
    shape=None,
    name=None
)

placeholder 是 Tensorflow 中的占位符,若是想要从外部传入data, 那就须要用到 tf.placeholder(),而后以这种形式传输数据 sess.run(***, feed_dict={input: **})传入数据。code

placeholder 与 feed_dict={} 是绑定在一块儿出现的;这里没有变量,就不须要在上两个笔记的 init =tf.global_variables_initializer() 这一步了。blog

具体练习的代码:ip

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.]input

相关文章
相关标签/搜索