TF随笔-9
计算累加
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 24 08:25:41 2017
求1+...+5
@author: myhaspl@myhaspl.com
"""
import tensorflow as tf
i = tf.constant(0)
num_sum=tf.Variable(0)
def cond(i,num_sum):
return i <=5
def body(i,num_sum):
num_sum+=i
i+=1
return (i,num_sum)
i,num_sum= tf.while_loop(cond, body, [i,num_sum])
with tf.Session() as sess:
tf.global_variables_initializer().run()
res = sess.run([i,num_sum])
print res
print res[1]
print 1+2+3+4+5
tensorflow的循环
执行结果
[6, 15]
15
15
TF随笔-9的更多相关文章
- TF随笔-13
import tensorflow as tf a=tf.constant(5) b=tf.constant(3) res1=tf.divide(a,b) res2=tf.div(a,b) with ...
- TF随笔-11
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import tensorflow as tf my_var=tf.Variable(0.) step=t ...
- TF随笔-10
#!/usr/bin/env python# -*- coding: utf-8 -*-import tensorflow as tf x = tf.constant(2)y = tf.constan ...
- TF随笔-8
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Mon Jul 10 09:35:04 201 ...
- TF随笔-7
求平均值的函数 reduce_mean axis为1表示求行 axis为0表示求列 >>> xxx=tf.constant([[1., 10.],[3.,30.]])>> ...
- tf随笔-6
import tensorflow as tfx=tf.constant([-0.2,0.5,43.98,-23.1,26.58])y=tf.clip_by_value(x,1e-10,1.0)ses ...
- tf随笔-5
# -*- coding: utf-8 -*-import tensorflow as tfw1=tf.Variable(tf.random_normal([2,6],stddev=1))w2=tf. ...
- TF随笔-4
>>> import tensorflow as tf>>> a=tf.constant([[1,2],[3,4]])>>> b=tf.const ...
- TF随笔-3
>>> import tensorflow as tf>>> node1 = tf.constant(3.0, dtype=tf.float32)>>& ...
随机推荐
- 20145302张薇《Java程序设计》第六周学习总结
20145302 <Java程序设计>第六周学习总结 教材学习内容总结 第十章 串流设计的概念 无论来源和目的地实体形式是什么,只要取得InputStream和OutputStream实例 ...
- STC51几种简单的延时函数
STC51几种简单的延时函数 ,* 延时子程序 * * * ********************************************************************** ...
- kafka运行错误:提示找不到或者无法加载主类错误解决方法
kafaka版本:kafka_2.11-1.1.0原因有2个:1 目录不能有空格 D:\Soft\kafka_2.11-1.1.0 , 放在Program Files目录中一直有问题2 修改D ...
- SaltStack高可用multi-master-第十三篇
multi-master官方介绍 As of Salt 0.16.0, the ability to connect minions to multiple masters has been made ...
- C# 往string [] arr 数组插入元素
string [] arr ; List<string> _list = new List<string>(arr ); for(int i ;i<10;i++) { _ ...
- codeforces27D Ring Road 2
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- 1023: Pong’s Birds(概率)
1023: Pong’s Birds 时间限制: 1 Sec 内存限制: 128 MB提交: 94 解决: 21[提交][状态][讨论版] 题目描述 In order to train his b ...
- ORM--------Hibernate、Mybatis与Spring Data的区别
1.概念: Hibernate :Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库.着力点对象 ...
- 【Raspberry pi】cpu、内存等查看及扩展
使用树莓派时,需要在其系统中部署几个不同功能的程序系统,并涉及到数据库读写.串口读写.web访问等,使系统使用压力较大,在查看树莓派使用情况时也遇到些许问题. free命令 total used fr ...
- Ansible 小手册系列 十三(Jinja2)
用于playbook中的jinja 2过滤器 更改数据格式,其结果是字符串 {{ some_variable | to_json }} {{ some_variable | to_yaml }} 对于 ...