02_Tensorflow基础操作 -- 常量,矩阵相乘
2018-03-16 16:03
363 查看
# python2.7 # Basic Operations example using TensorFlow library. # Author: Aymeric Damien # Project: https://github.com/aymericdamien/TensorFlow-Examples/ import tensorflow as tf a = tf.constant(2) b = tf.constant(3) # Launch the default graph. with tf.Session() as sess: print "a: %i" % sess.run(a), "b: %i" % sess.run(b) print "Addition with constants: %i" % sess.run(a+b) print "Multiplication with constants: %i" % sess.run(a*b)
# 占位符 a = tf.placeholder(tf.int16) b = tf.placeholder(tf.int16) # Define some operations add = tf.add(a, b) mul = tf.multiply(a, b) # Launch the default graph. with tf.Session() as sess: # Run every operation with variable input 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})
# More in details: # Matrix Multiplication from TensorFlow official tutorial matrix1 = tf.constant([[3., 3.]]) # Create another Constant that produces a 2x1 matrix. matrix2 = tf.constant([[2.],[2.]]) product = tf.matmul(matrix1, matrix2) # The output of the op is returned in 'result' as a numpy `ndarray` object. with tf.Session() as sess: result = sess.run(product) print result
以上代码同样可以用python3进行操作,只要将print 改成print()即可。
相关文章推荐
- tensorflow 学习专栏(二):tensorflow基础操作 常量加乘 矩阵乘
- Tensorflow深度学习之三:基础概念篇(矩阵相乘)
- TensorFlow基础知识点(六)/矩阵基本操作
- TensorFLow 基础 矩阵相乘相加 线性回归 手写字体逻辑回归 神经网络 tensorboard 显示 网络结构 和 优化记录
- 黑马程序员--02.Java语言基础--01.【关键字】【标示符】【常量】【变量】【运算符】
- 番外 02: Spring 之使用 JAVA 操作Mysql数据库(为何要用ORM)Spring整合 Mybatis前基础
- 暑期 tensorflow 基础操作笔记
- java基础(6)数组的操作--打印矩阵
- ORACLE基础操作【02】 -->split分区表
- 番外 02: Spring 之使用 JAVA 操作Mysql数据库(为何要用ORM)Spring整合 Mybatis前基础
- 笔记 .Net 进阶分享 02 基础操作
- 02_Swift2基础之常量和变量+注释+分号
- 番外 02: Spring 之使用 JAVA 操作Mysql数据库(为何要用ORM)Spring整合 Mybatis前基础
- elasticsearch基础操作02
- 【机器学习数学基础之矩阵02】矩阵求导
- Java基础-02总结关键字,标识符,注释,常量进制,变量数据类型
- 番外 02: Spring 之使用 JAVA 操作Mysql数据库(为何要用ORM)Spring整合 Mybatis前基础
- 开源Math.NET基础数学类库使用(02)矩阵向量计算
- TF:Tensorflow之session会话的使用,定义两个矩阵,两种方法输出2个矩阵相乘的结果—Jason niu
- Matlab矩阵操作基础,学习笔记...