tensorflow学习之,四使用placeholder 传入值

#placeholder 传入值
import tensorflow as tf

"""
tf.Variable:主要在于一些可训练变量(trainable variables),比如模型的权重(weights,W)或者偏执值(bias):
    声明时,必须提供初始值;
    名称的真实含义,在于变量,也即在真实训练时,其值是会改变的,自然事先需要指定初始值; 
tf.placeholder:用于得到传递进来的真实的训练样本:
    不必指定初始值,可在运行时,通过 Session.run 的函数的 feed_dict 参数指定;
    这也是其命名的原因所在,仅仅作为一种占位符;
"""
input1 = tf.placeholder(tf.float32)#默认是float32的形式
input2 = tf.placeholder(tf.float32)

output = tf.multiply(input1,input2)

with tf.Session() as sess:
    print(sess.run(output,feed_dict={input1:[7.0],input2:[2.0]}))#以字典的形式传值给output