莫烦TensorFlow_03 Variable加法

import tensorflow as tf  
## 定义变量  
state = tf.Variable(0, name = 'counter')  
#print(state.name)  
one = tf.constant(1)  
## 定义计算  
new_value = tf.add(state, one)  
update = tf.assign(state, new_value)  
## 定义初始化  
init = tf.initialize_all_variables() # important  
## 执行  
with tf.Session as sess:  
  sess.run(init)  
  for _ in range(3):  
    sess.run(update)  
    print(sess.run(state)  

  

 

加法

累加1

加3次

posted @ 2018-03-31 21:05  路边的十元钱硬币  阅读(154)  评论(0编辑  收藏  举报