TensorFlow 基本变量定义,基本操作,矩阵基本操作
来源:互联网 发布:免费手机网络电话软件 编辑:程序博客网 时间:2024/06/05 15:04
使用 TensorFlow 进行基本操作的实例,这个实例主要是使用 TensorFlow 进行了加法运算。 包括使用 constant 常量进行加法运算和使用 placeholder 进行变量加法运算,以及扩展到矩阵的加法运算。 TensorFlow 变量定义,加法运算。
# -*- coding:utf-8 -*-from __future__ import print_function'''使用 TensorFlow 进行基本操作的实例,这个实例主要是使用 TensorFlow 进行了加法运算。包括使用 constant 常量进行加法运算和使用 placeholder 进行变量加法运算,以及扩展到矩阵的加法运算。TensorFlow 变量定义,加法运算。''''''Basic Operations example using TensorFlow library.Author: Aymeric DamienProject: https://github.com/aymericdamien/TensorFlow-Examples/'''import tensorflow as tf# Basic constant operations# The value returned by the constructor represents the output# of the Constant op.a = tf.constant(2)b = tf.constant(3)# Launch the default graph.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))# Basic Operations with variable as graph input# The value returned by the constructor represents the output# of the Variable op. (define as input when running session)# tf Graph inputa = tf.placeholder(tf.int16)b = tf.placeholder(tf.int16)# Define some operationsadd = 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# Create a Constant op that produces a 1x2 matrix. The op is# added as a node to the default graph.## The value returned by the constructor represents the output# of the Constant op.matrix1 = tf.constant([[3., 3.]])# Create another Constant that produces a 2x1 matrix.matrix2 = tf.constant([[2.],[2.]])# Create a Matmul op that takes 'matrix1' and 'matrix2' as inputs.# The returned value, 'product', represents the result of the matrix# multiplication.product = tf.matmul(matrix1, matrix2)# To run the matmul op we call the session 'run()' method, passing 'product'# which represents the output of the matmul op. This indicates to the call# that we want to get the output of the matmul op back.## All inputs needed by the op are run automatically by the session. They# typically are run in parallel.## The call 'run(product)' thus causes the execution of threes ops in the# graph: the two constants and matmul.## 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) # ==> [[ 12.]]查看更多 TensorFlow 教程:http://www.tensorflownews.com/
阅读全文
0 0
- TensorFlow 基本变量定义,基本操作,矩阵基本操作
- Matlab矩阵基本操作(定义,运算)
- Matlab矩阵基本操作(定义,运算)
- Matlab矩阵基本操作(定义,运算)
- Matlab矩阵基本操作(定义,运算)
- TensorFlow 基本操作
- Tensorflow-基本操作基本知识
- 53、tensorflow基本操作
- TensorFlow基本操作(二)
- matlab矩阵基本操作
- 矩阵基本操作
- openCV矩阵基本操作
- numpy基本矩阵操作
- numpy - 矩阵基本操作
- matlab矩阵基本操作
- matlab基本矩阵操作
- opencv基本矩阵操作
- numpy基本矩阵操作
- java(== and equals)
- 欢迎使用CSDN-markdown编辑器
- Android 自定义Dialog
- Java String
- 动态规划的背包问题 (共六题)
- TensorFlow 基本变量定义,基本操作,矩阵基本操作
- 大数加法 自定义函数
- vue.js使用总结
- python——asyncio模块实现协程、异步编程(二)
- java 泛型
- 最简单的 TensorFlow 代码,TensorFlow Hello World 。
- ORACLE物化视图
- 关于Java中值传递还是引用传递的问题解析-------引用校招笔试中的一道题进行解释
- [BZOJ1512][VijosP1006]晴天小猪历险记