最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
基于tensorflow for循环while循环代码示例
时间:2020-06-30 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下基于tensorflow for循环while循环代码示例,代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
代码如下:
import tensorflow as tf n1 = tf.constant(2) n2 = tf.constant(3) n3 = tf.constant(4) def cond1(i, a, b): return i < n1 def cond2(i, a, b): return i < n2 def cond3(i, a, b): return i < n3 def body(i, a, b): return i + 1, b, a + b i1, a1, b1 = tf.while_loop(cond1, body, (2, 1, 1)) i2, a2, b2 = tf.while_loop(cond2, body, (2, 1, 1)) i3, a3, b3 = tf.while_loop(cond3, body, (2, 1, 1)) sess = tf.Session() print(sess.run(i1)) print(sess.run(a1)) print(sess.run(b1)) print("-") print(sess.run(i2)) print(sess.run(a2)) print(sess.run(b2)) print("-") print(sess.run(i3)) print(sess.run(a3)) print(sess.run(b3))
print结果:
2 1 1 - 3 1 2 - 4 2 3
可见body函数返回的三个变量又传给了body
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27