创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!
小编给大家分享一下关于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))