生成新的计算图,并完成常量初始化,在新的计算 图中完成加法计算

import tensorflow as tf

g1=tf.Graph()

with g1.as_default():

value=[1.,2.,3.,4.,5.,6.]

init = tf.constant_initializer(value)

x=tf.get_variable("x",initializer=init,shape=[2,3])

y=tf.get_variable("y",shape=[2,3],initializer=tf.ones_initializer())

result=tf.add(x,y,name="myadd")

with tf.Session(graph=g1) as sess:

tf.global_variables_initializer().run()

with tf.variable_scope("",reuse=True):

print(sess.run(tf.get_variable("x")))

print(sess.run(tf.get_variable("y")))

print(sess.run(result))

输出结果

[[ 1.  2.  3.]
 [ 4.  5.  6.]]
[[ 1.  1.  1.]
 [ 1.  1.  1.]]
[[ 2.  3.  4.]
 [ 5.  6.  7.]]

tf随笔-1的更多相关文章

  1. TF随笔-13

    import tensorflow as tf a=tf.constant(5) b=tf.constant(3) res1=tf.divide(a,b) res2=tf.div(a,b) with ...

  2. TF随笔-11

    #!/usr/bin/env python2 # -*- coding: utf-8 -*- import tensorflow as tf my_var=tf.Variable(0.) step=t ...

  3. TF随笔-10

    #!/usr/bin/env python# -*- coding: utf-8 -*-import tensorflow as tf x = tf.constant(2)y = tf.constan ...

  4. TF随笔-9

    计算累加 #!/usr/bin/env python2 # -*- coding: utf-8 -*-"""Created on Mon Jul 24 08:25:41 ...

  5. TF随笔-8

    #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Mon Jul 10 09:35:04 201 ...

  6. TF随笔-7

    求平均值的函数 reduce_mean axis为1表示求行 axis为0表示求列 >>> xxx=tf.constant([[1., 10.],[3.,30.]])>> ...

  7. tf随笔-6

    import tensorflow as tfx=tf.constant([-0.2,0.5,43.98,-23.1,26.58])y=tf.clip_by_value(x,1e-10,1.0)ses ...

  8. tf随笔-5

    # -*- coding: utf-8 -*-import tensorflow as tfw1=tf.Variable(tf.random_normal([2,6],stddev=1))w2=tf. ...

  9. TF随笔-4

    >>> import tensorflow as tf>>> a=tf.constant([[1,2],[3,4]])>>> b=tf.const ...

  10. TF随笔-3

    >>> import tensorflow as tf>>> node1 = tf.constant(3.0, dtype=tf.float32)>>& ...

随机推荐

  1. Delphi 正则表达式之TPerlRegEx 类的属性与方法(2): 关于子表达式

    Delphi 正则表达式之TPerlRegEx 类的属性与方法(2): 关于子表达式 // MatchedExpression 与 SubExpressions[0] var   reg: TPerl ...

  2. python之路 IO多路复用 线程进程初步了解

    一.IO多路复用 1.客户端 #!/usr/bin/env python #-*-coding:utf-8-*- import socket sk=socket.socket() sk.connect ...

  3. 如何选择单片机和Android-LInux-ARM开发板?

    源: 如何选择单片机和Android-LInux-ARM开发板?

  4. CF932E Team Work(第二类斯特林数)

    题目 CF932E Team Work 前置:斯特林数\(\Longrightarrow\)点这里 做法 \[\begin{aligned}\\ &\sum\limits_{i=1}^n C_ ...

  5. Rreact Native 常见错误总结

    1.invariant violation:expected a component class,got[object object]        创建自定义组件首字母要大写,否则会报错.     ...

  6. v4l2 下载

    To clone the master development repository, install git, and run: git clone git://github.com/torvald ...

  7. iOS基于XMPP实现即时通讯之一、环境的搭建

    移动端访问不佳,请访问我的个人博客 使用XMPP已经有一段时间了,但是一直都没深入研究过,只是使用SDK做一些简单的操作,看了许多大神的博客,自己总结一下,准备写一系列关于XMPP的使用博客,以便于自 ...

  8. 2.scala控制结构、函数、异常处理

    2.scala控制结构.函数.异常处理---小书匠,在线编辑器,MARKDOWN,Evernote,文件版本 a:focus { outline: thin dotted #333; outline: ...

  9. 谷歌SEO老域名注册完全攻略

    老域名有优势,不管在百度和谷歌都是一样的. 我们查看搜索结果就能发现,谷歌里面很多排前十的网站都是N年前的,一零年以后的算是比较新的,很多产品网站域名是零几年,甚至很多排名更好的域名是九几年的. 谷歌 ...

  10. JavaWeb -- Struts 数据传输:OGNL和类型转换

    1. 数据传输:OGNL和类型转换 OGNL和struts2 OGNL:Object-Graph Navigation Language. OGNL是集成进struts框架中比较强大的技术有助于数据传 ...