#计数器

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)

x = np.random.rand(3,2) #测试非tensor变量

t =  tf.convert_to_tensor(x, dtype=tf.float32) #tf.convert_to_tensor(...)这个方法,我们可以用在任何地方,以确保我们处理张量而不是其他类型

init = tf.initialize_all_variables() #重要,初始化变量
#sess = tf.Session()
#sess.run(init)
with tf.Session() as sess:
sess.run(init)
for _ in range(3):
sess.run(update)
print(sess.run(state))

备注:

如果执行过程中遇到<class ‘tensorflow.python.framework.ops.Tensor’>,是类型不对导致,因为TensorFlow中所有运算符(如neg)都设计为对张量对象进行操作

最新文章

  1. Dom学习笔记
  2. Power BI Q&amp;A终于在圣诞前夕盼到
  3. vb.net三层实现登录例子
  4. MYSQL PASSWORD()
  5. c语言知识点总结(摘自head first c)
  6. 学点PYTHON基础的东东--数据结构,算法,设计模式---访问者模式
  7. Java中字符串indexof() 的使用方法
  8. Linux(二十一)Shell编程
  9. lambda表达式中的排序问题
  10. Hdoj 2109.Fighting for HDU 题解
  11. show full processlist
  12. js数组的操作push,pop,shift,unshift
  13. Delphi DBGrid记录全选和反选拖动处理
  14. Excel学习笔记:sumif、sumifs、countifs函数使用方法
  15. org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.xugao.bean.MemberLevel.memberpointrate
  16. 第四节:Windows系统安装时BIOS设置及注意
  17. Windows Server 2003 R2 IIS服务的命令行方式重启命令
  18. 【RF库Collections测试】Get From List
  19. C++ 线程学习
  20. 【转】 线段树完全版 ~by NotOnlySuccess

热门文章

  1. NB群友
  2. 收藏vue技术内幕
  3. 关于because the weaver option &#39;-Xset:weaveJavaxPackages=true&#39; has not been specified报错的解决方案
  4. Linux系统(虚拟机)安装禅道
  5. kmp算法 模板
  6. IntelliJ IDEA安装ideaIU-2019.1
  7. selenium截图
  8. PADS Layout VX.2.3 制作PCB封装(Decal)时,导入DXF文件
  9. SpringBoot的事件监听
  10. Codeforces 438E. The Child and Binary Tree 多项式,FFT