tensorflow-变量
2024-10-12 16:43:22
#计数器
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)都设计为对张量对象进行操作
最新文章
- Dom学习笔记
- Power BI Q&;A终于在圣诞前夕盼到
- vb.net三层实现登录例子
- MYSQL PASSWORD()
- c语言知识点总结(摘自head first c)
- 学点PYTHON基础的东东--数据结构,算法,设计模式---访问者模式
- Java中字符串indexof() 的使用方法
- Linux(二十一)Shell编程
- lambda表达式中的排序问题
- Hdoj 2109.Fighting for HDU 题解
- show full processlist
- js数组的操作push,pop,shift,unshift
- Delphi DBGrid记录全选和反选拖动处理
- Excel学习笔记:sumif、sumifs、countifs函数使用方法
- org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.xugao.bean.MemberLevel.memberpointrate
- 第四节:Windows系统安装时BIOS设置及注意
- Windows Server 2003 R2 IIS服务的命令行方式重启命令
- 【RF库Collections测试】Get From List
- C++ 线程学习
- 【转】 线段树完全版 ~by NotOnlySuccess
热门文章
- NB群友
- 收藏vue技术内幕
- 关于because the weaver option &#39;-Xset:weaveJavaxPackages=true&#39; has not been specified报错的解决方案
- Linux系统(虚拟机)安装禅道
- kmp算法 模板
- IntelliJ IDEA安装ideaIU-2019.1
- selenium截图
- PADS Layout VX.2.3 制作PCB封装(Decal)时,导入DXF文件
- SpringBoot的事件监听
- Codeforces 438E. The Child and Binary Tree 多项式,FFT