tensorflow-条件循环控制(3)

tf.count_up_to
tf.count_up_to(
    ref,
    limit,
    name=None
)

增加“ref”直到它达到“limit”

参数:

ref:一个变量,必须是int32, int64类型。必要来自于一个 scalar Variable 节点
limit:一个int,如果增加ref在limit之上,将报错 'OutOfRange' 。
name: 操作名字(可选)
返回:

tensor,和ref类型相同,在增长之前输入的副本,如果没有其他修改输入,所产生的值将是不同的。


#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 27 11:16:32 2018
@author: myhaspl
"""

import tensorflow as tf
x = tf.Variable(0, name="my_x")
add_var=tf.count_up_to(x,1000)

init_op = tf.global_variables_initializer()
sess=tf.Session()
with sess: 
    sess.run(init_op)
    print sess.run(add_var)
    print x.eval()
    print sess.run(add_var)
    print x.eval()

01
1
2

猜你喜欢

转载自blog.51cto.com/13959448/2333007
今日推荐