tensorflow入门之placeholder

来源:互联网 发布:用友t3软件下载 编辑:程序博客网 时间:2024/04/30 15:08

tensorflow中又一保存数据的利器,placeholder(type,strucuct…)它的第一个参数是你要保存的数据的数据类型,大多数是tensorflow中的float32数据类型,后面的参数就是要保存数据的结构,比如要保存一个1×2的矩阵,则struct=[1 2]。它在使用的时候和前面的variable不同的是在session运行阶段,需要给placeholder提供数据,利用feed_dict的字典结构给placeholdr变量“喂数据”,具体使用如下:

# -*- coding: utf-8 -*-"""Created on Mon Apr  3 11:20:22 2017@author: zhangshaoxing"""import tensorflow as tfa=tf.placeholder(tf.float32)b=tf.placeholder(tf.float32)c=tf.add(a,b)with tf.Session() as sess:    print(sess.run(c,feed_dict={a:10,b:30}))  #把10赋给a,30赋给b

运行结果:

40.0
2 0