比中国足球更sb的球队,百变大咖秀陈翔,创造情缘剧情介绍
import tensorflow as tf # 定义两个常数,a和b a = tf.constant(2) b = tf.constant(3) # 执行默认图运算 with tf.session() as sess: print("a=2, b=3") print("addition with constants: %i" % sess.run(a+b)) print("multiplication with constants: %i" % sess.run(a*b))
结果
a=2, b=3
addition with constants: 5
multiplication with constants: 6
变量作为图形输入,构造器的返回值作为变量的输出,在运行会话时,传入变量的值,在进行运算。
import tensorflow as tf # 定义两个变量 a = tf.placeholder(tf.int16) b = tf.placeholder(tf.int16) # 定义加法和乘法运算 add = tf.add(a, b) mul = tf.multiply(a, b) # 启动默认图进行运算 with tf.session() as sess: # 传入变量值,进行运算 print("addition with variables: %i" % sess.run(add, feed_dict={a: 2, b: 3})) print("multiplication with variables: %i" % sess.run(mul, feed_dict={a: 2, b: 3}))
结果
addition with variables: 5
multiplication with variables: 6
import tensorflow as tf # 创建一个1x2的常数矩阵 matrix1 = tf.constant([[3., 3.]]) # 创建一个2x1的常数矩阵 matrix2 = tf.constant([[2.],[2.]]) # 定义矩阵乘法运算multiplication product = tf.matmul(matrix1, matrix2) # 启动默认图进行运算 with tf.session() as sess: result = sess.run(product) print(result)
结果
[[12.]]
import tensorflow as tf hello = tf.constant('hello, tensorflow!') sess = tf.session() print(sess.run(hello))
结果
b'hello, tensorflow!'
参考:
author: aymeric damien
project: https://github.com/aymericdamien/tensorflow-examples/
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Python 实现将numpy中的nan和inf,nan替换成对应的均值
python爬虫把url链接编码成gbk2312格式过程解析
网友评论