机器学习系列-tensorflow-02-基本操作运算
tensorflow常数操作
```
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
tensorflow变量操作
变量作为图形输入,构造器的返回值作为变量的输出,在运行会话时,传入变量的值,在进行运算。
```
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
----------------------
<h1 style="background-color:#FF69B4; font-family:verdana; font-size:25px; text-align:center; font-weight:bold; color:white; ">tensorflow矩阵常量操作</h1>
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.]]
<h1 style="background-color:#FF69B4; font-family:verdana; font-size:25px; text-align:center; font-weight:bold; color:white; ">简单例子</h1>
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/
机器学习系列-tensorflow-02-基本操作运算的更多相关文章
- Weka中数据挖掘与机器学习系列之Exploer界面(七)
不多说,直接上干货! Weka的Explorer(探索者)界面,是Weka的主要图形化用户界面,其全部功能都可通过菜单选择或表单填写进行访问.本博客将详细介绍Weka探索者界面的图形化用户界面.预处理 ...
- Weka中数据挖掘与机器学习系列之Weka系统安装(四)
能来看我这篇博客的朋友,想必大家都知道,Weka采用Java编写的,因此,具有Java“一次编译,到处运行”的特性.支持的操作系统有Windows x86.Windows x64.Mac OS X.L ...
- TortoiseGit学习系列之TortoiseGit基本操作拉取项目(图文详解)
前面博客 TortoiseGit学习系列之TortoiseGit基本操作克隆项目(图文详解) TortoiseGit学习系列之TortoiseGit基本操作修改提交项目(图文详解) TortoiseG ...
- TortoiseGit学习系列之TortoiseGit基本操作将提交到本地的项目推送到在线仓库(图文详解)
前面博客 TortoiseGit学习系列之TortoiseGit基本操作克隆项目(图文详解) TortoiseGit学习系列之TortoiseGit基本操作修改提交项目(图文详解) TortoiseG ...
- TortoiseGit学习系列之TortoiseGit基本操作修改提交项目(图文详解)
前面博客 TortoiseGit学习系列之TortoiseGit基本操作克隆项目(图文详解) TortoiseGit基本操作修改提交项目 项目克隆完成后(可以将克隆 clone 理解为 下载,检出 c ...
- Git学习系列之Git基本操作拉取项目(图文详解)
前面博客 Git学习系列之Git基本操作推送项目(图文详解) 当然,如果多人协作,或者多个客户端进行修改,那么我们还要拉取(Pull ... )别人推送到在线仓库的内容下来. 大神们是不推荐使用 pu ...
- Git学习系列之Git基本操作推送项目(图文详解)
前面博客 Git学习系列之Git基本操作提交项目(图文详解) 如果完成到一定程度,那么可以推送到远端在线仓库. 推送之前,请确保你已经设置了全局的 user.name 和 user.email, 如果 ...
- Git学习系列之Git基本操作提交项目(图文详解)
前面博客 Git学习系列之Git基本操作克隆项目(图文详解) 然后可以 cd 切换到 LispGentleIntro 目录, 新增或者修改某些文件.这里只是模拟一下操作, 实际情况可能是 使用 Ecl ...
- Spark2.0机器学习系列之10: 聚类(高斯混合模型 GMM)
在Spark2.0版本中(不是基于RDD API的MLlib),共有四种聚类方法: (1)K-means (2)Latent Dirichlet allocation (LDA) ...
随机推荐
- linux添加自定义命令
想添加一个命令, 比如我输入 cdms 按回车, 然后就执行了: cd /mnt/gopath/src/test/app/ 这条命令方法: vi /etc/bashrc 在文件末尾添加 alias c ...
- SQL 查询表的第一条数据 和 最后一条数据
方法一: 使用TOP SELECT TOP 1 * FROM user; SELECT TOP 1 * FROM user order by id desc; 方法二: 使用LIMIT SELECT ...
- Centos7+ASP.Net Core 运行
一:ASP.Net Core跨平台运行,需要在Linux安装运行环境.本机器使用的Centos,下载安装地址为:https://www.microsoft.com/net/core#centos su ...
- net-snmp 安装与trap调试
https://sourceforge.net/projects/net-snmp/files/net-snmp/5.7.3/
- php抽奖概率算法
方法一: function get_rand($proArr) { $result = array(); foreach ($proArr as $key => $val) { $arr[$ke ...
- Note for "Some Remarks on Writing Mathematical Proofs"
John M. Lee is a famous mathematician, who bears the reputation of writing the classical book " ...
- Django时区的解释
https://segmentfault.com/q/1010000000405911
- python manage.py runserver指定端口和ip
python manage.py runserver 0.0.0.0:8000 在本地运行程序,python manager.py runserver打开http://127.0.0.1:5000端口 ...
- Flink--输入数据集Data Sources
flink在批处理中常见的source flink在批处理中常见的source主要有两大类. 1.基于本地集合的source(Collection-based-source) 2.基于文件的sourc ...
- 2018牛客网暑假ACM多校训练赛(第三场)D Encrypted String Matching 多项式 FFT
原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-D.html 题目传送门 - 2018牛客多校赛第三场 D ...