tensorflow随笔-条件循环控制(11)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010255642/article/details/82454849
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 27 11:16:32 2018
@author: myhaspl
"""
 
import tensorflow as tf
i0 = tf.constant(0)
m0 = tf.ones([2, 2])
c = lambda i, m: i < 5
b = lambda i, m: [i+1, tf.concat([m, m], axis=0)]
ijk_final=tf.while_loop(
    c, b, loop_vars=[i0, m0],
    shape_invariants=[i0.get_shape(), tf.TensorShape([None, 2])])


sess=tf.Session()
with sess:
    print sess.run(ijk_final)
[5, array([[1., 1.],
       [1., 1.],
       [1., 1.],
       ...,
       [1., 1.],
       [1., 1.],
       [1., 1.]], dtype=float32)]
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 27 11:16:32 2018
@author: myhaspl
"""
 
import tensorflow as tf
i0 = tf.constant(0)
m0 = tf.ones([2, 2])
c = lambda i, m: i < 5
b = lambda i, m: [i+1, tf.concat([m+1, m], axis=0)]
ijk_final=tf.while_loop(
    c, b, loop_vars=[i0, m0],
    shape_invariants=[i0.get_shape(), tf.TensorShape([None, 2])])


sess=tf.Session()
with sess:
    print sess.run(ijk_final)
[5, array([[6., 6.],
       [6., 6.],
       [5., 5.],
       ...,
       [2., 2.],
       [1., 1.],
       [1., 1.]], dtype=float32)]

形状不变量tf.TensorShape([None, 2])控制了m的形状 为任意行,2列

猜你喜欢

转载自blog.csdn.net/u010255642/article/details/82454849
今日推荐