AI学习之路(20)占位符(placeholder)的使用

在编写TF程序里,经常会有一些待输入的参数,但是在建立模型时,需要使用到它,那么就需要使用占用符的方式来写入计算公式里,也就是建立到模型里的关系。

下面就是一个使用占位符的例子:

#python 3.5.3      
#2017-03-13 蔡军生  http://blog.csdn.net/caimouse    
#
import tensorflow as tf
import numpy as np

x = tf.placeholder(tf.float32, shape=(1024, 1024))
y = tf.matmul(x, x)
with tf.Session() as sess:
    rand_array = np.random.rand(1024, 1024)
    print(sess.run(y, feed_dict={x: rand_array}))  # Will succeed.

输出结果如下:

======== RESTART: D:/work/csdn/tensorflow/line/TF_1.0_placeholder1.py ========
[[ 250.13143921  259.39517212  253.62782288 ...,  259.89556885
   252.14181519  248.71147156]
 [ 259.01690674  262.79354858  260.86987305 ...,  265.65951538
   265.07470703  249.14387512]
 [ 272.46600342  274.78189087  269.41098022 ...,  282.14144897
   271.10812378  266.05484009]
 ..., 
 [ 256.34280396  265.10443115  261.69354248 ...,  265.37792969
   258.57714844  250.93035889]
 [ 259.50469971  265.48266602  259.76217651 ...,  269.34823608
   264.03543091  253.12931824]
 [ 247.76449585  258.01040649  256.93270874 ...,  262.97912598
   255.13204956  245.21099854]]
>>>


1. TensorFlow入门基本教程

2. C++标准模板库从入门到精通 

3.跟老菜鸟学C++

4. 跟老菜鸟学python

5. 在VC2015里学会使用tinyxml库

6. 在Windows下SVN的版本管理与实战 

 http://edu.csdn.net/course/detail/2579

7.Visual Studio 2015开发C++程序的基本使用 

http://edu.csdn.net/course/detail/2570

8.在VC2015里使用protobuf协议

9.在VC2015里学会使用MySQL数据库



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

caimouse

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值