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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章