首页 > 其他 > 详细

tensorflow 笔记

时间:2019-05-16 16:10:11      阅读:90      评论:0      收藏:0      [点我收藏+]

1. matMul

#-*-coding:utf-8 -*-

import tensorflow as tf w1 = tf.Variable(tf.random_normal([2,3], stddev= 1, seed= 1)) w2 = tf.Variable(tf.random_normal([3,1], stddev= 1, seed= 1)) x = tf.constant([[0.7, 0.9]]) # 1×2 a = tf.matmul(x, w1) # 1×3 y = tf.matmul(a, w2) # 1×1 sess = tf.Session() # w1 w2 sess.run(w1.initializer) sess.run(w2.initializer) sess.run(y) print(y) sess.close()

 

2. eval 函数 作用: 

1.eval(): 将字符串string对象转化为有效的表达式参与求值运算返回计算结果
2.eval()也是启动计算的一种方式。基于Tensorflow的基本原理,首先需要定义图,然后计算图,其中计算图的函数常见的有run()函数,如sess.run()。同样eval()也是此类函数,
3.要注意的是,eval()只能用于tf.Tensor类对象,也就是有输出的Operation。对于没有输出的Operation, 可以用.run()或者Session.run();Session.run()没有这个限制。

import tensorflow as tf

x = tf.Variable(3, name="x")
y = tf.Variable(4, name="y")
z = tf.Variable(4, name="z")
w = tf.Variable(4, name="w")
f = x * y * z + 3 - w

//单个初始化,变量增多,还真是个事
with tf.Session() as sess:
    x.initializer.run()
    y.initializer.run()
    z.initializer.run()
    w.initializer.run()
    print(x)
    print(y)
    print(z)
    print(w)
   //f fuction eval 方式和js的eval一样,作为方法函数执行
    result = f.eval()
 print(result)

 

tensorflow 笔记

原文:https://www.cnblogs.com/luoyinjie/p/10875569.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!