Tensorflow | 基本函数介绍
2017-01-18 23:04
441 查看
这次来总结下这几天学习tensorflow的心得,包含了一些基本的函数,例如,加减乘除等,下面来一一介绍,并给出具体的例子。
两个小的tips
我的版本:anaconda 4.2 tensorflow 0.12.1
若是你不知道如何在windows下安装tensorflow,可以依照我的博客:http://blog.csdn.net/xxzhangx/article/details/54379255 ,遵循上面的顺序来做;若是安装过程中遇到问题,可以在博客下方留言,看到后会及时回答。
结果:9.0
结果:6.0
结果: 0.0
结果: 1.0
结果: 0.0
结果: 3.0
结果: 3.0
结果: 3.0
结果: -1.0
结果: -1.0
结果: 9.0
结果: -4.0
例如: a=-3.3,round(a) = -3.0
结果:-3.0
结果: 2.0
结果: 8.0
结果: 7.38906
结果: 0.69314718056
结果: 2.0
结果: 2.0
结果: -0.416146836547
结果: 0.909297426826
两个小的tips
我的版本:anaconda 4.2 tensorflow 0.12.1
若是你不知道如何在windows下安装tensorflow,可以依照我的博客:http://blog.csdn.net/xxzhangx/article/details/54379255 ,遵循上面的顺序来做;若是安装过程中遇到问题,可以在博客下方留言,看到后会及时回答。
数值乘法mul
例如:a=3,b=3,a*b = 9import tensorflow as tf a = tf.placeholder(tf.float32) b = tf.placeholder(tf.float32) y = tf.mul(a, b) sess = tf.Session() print (sess.run(y, feed_dict={a: 3, b: 3}))
结果:9.0
数值和add
例如: a = 3, b=3 ,a+b = 6import tensorflow as tf a = tf.placeholder(tf.float32) b = tf.placeholder(tf.float32) y = tf.add(a, b) sess = tf.Session() print (sess.run(y, feed_dict={a: 3, b: 3}))
结果:6.0
数值减法sub
例如:a=3,b=3,a-b = 0import tensorflow as tf a = tf.placeholder(tf.float32) b = tf.placeholder(tf.float32) y = tf.sub(a, b) sess = tf.Session() print (sess.run(y, feed_dict={a: 3, b: 3}))
结果: 0.0
数值除法div
例如: a=3,b=3,a/b = 1.0import tensorflow as tf a = tf.placeholder(tf.float32) b = tf.placeholder(tf.float32) y = tf.div(a, b) sess = tf.Session() print (sess.run(y, feed_dict={a: 3, b: 3}))
结果: 1.0
数值取模mod
例如:a=3,b=3,a mod b = 0import tensorflow as tf a = tf.placeholder(tf.float32) b = tf.placeholder(tf.float32) y = tf.mod(a, b) sess = tf.Session() print (sess.run(y, feed_dict={a: 3, b: 3}))
结果: 0.0
数值绝对值abs
例如:a=-3, abs (a) = 3import tensorflow as tf a = tf.placeholder(tf.float32) b = tf.placeholder(tf.float32) y = tf.abs(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3}))
结果: 3.0
数值非负值neg
例如:a=-3, neg (a) = 3import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.neg(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3}))
结果: 3.0
数值符号函数sign
例如:a=-3, neg (a) = 3import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.neg(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3}))
结果: 3.0
数值符号函数sign
例如: a=-3,sign(a) = -1import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.sign(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3}))
结果: -1.0
数值倒数inv
例如: a=-3,sign(a) = -1import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.sign(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3}))
结果: -1.0
数值平方square
例如: a=-3,square(a) = 9import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.square(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3}))
结果: 9.0
数值最近的整数round
例如: a=-3.6,round(a) = -4.0import tensorflow as tf y = tf.round(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3.6}))
结果: -4.0
例如: a=-3.3,round(a) = -3.0
import tensorflow as tf y = tf.round(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3.3}))
结果:-3.0
数值平方根sqrt
例如: a=4,sqrt(a) = 2import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.sqrt(a) sess = tf.Session() print (sess.run(y, feed_dict={a: 4}))
结果: 2.0
数值幂次pow
例如: a=2,b=3,pow(a,b) = 8import tensorflow as tf a = tf.placeholder(tf.float64) b = tf.placeholder(tf.float64) y = tf.pow(a, b) sess = tf.Session() print (sess.run(y, feed_dict={a: 2, b: 3}))
结果: 8.0
数值最近的整数exp
例如: a=2,exp(a) = 7.38906import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.exp(a) sess = tf.Session() print (sess.run(y, feed_dict={a: 2}))
结果: 7.38906
数值取对数log
例如: a=-3.6,round(a) = -4.0import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.log(a) sess = tf.Session() print (sess.run(y, feed_dict={a: 2}))
结果: 0.69314718056
数值取最大值maximum
例如: a=-3.6, b = 2,maximum(a,b)=2import tensorflow as tf a = tf.placeholder(tf.float32) b = tf.placeholder(tf.float32) y = tf.maximum(a,b) sess = tf.Session() print (sess.run(y, feed_dict={a: -3.6,b: 2}))
结果: 2.0
数值最小值minimum
例如: a=2,b=3minimum(a) = 3import tensorflow as tf a = tf.placeholder(tf.float64) b = tf.placeholder(tf.float64) y = tf.minimum(a, b) sess = tf.Session() print (sess.run(y, feed_dict={a: 2, b: 3}))
结果: 2.0
数值余弦函数cos
例如: a=2,cos(a) = -0.416146836547import tensorflow as tf a = tf.placeholder(tf.float64) y = tf.cos(a) sess = tf.Session() print (sess.run(y, feed_dict={a: 2}))
结果: -0.416146836547
数值正弦函数sin
例如: a=2,sin(a) = -0.416146836547import tensorflow as tf a = tf.placeholder(tf.float64) y = tf.sin(a) sess = tf.Session() print (sess.run(y, feed_dict={a: 2}))
结果: 0.909297426826
相关文章推荐
- SQLite基本函数介绍
- Tensorflow一些常用基本概念与函数(1)
- Tensorflow一些常用基本概念与函数(1)
- tensorflow常用函数介绍
- Tensorflow一些常用基本概念与函数(1)
- Tensorflow的基本概念与常用函数
- Tensorflow一些常用基本概念与函数(1)
- 小记tensorflow-1:tf.nn.conv2d 函数介绍
- Tensorflow一些常用基本概念与函数
- POSIX多线程——基本线程管理函数介绍
- Tensorflow一些常用基本概念与函数(1)
- [置顶] Tensorflow常用基本概念与函数
- tensorflow中的基本函数和意思
- SQL Server基本函数详细介绍
- c#中函数基本操作符介绍
- Tensorflow一些常用基本概念与函数(二)
- Tensorflow一些常用基本概念与函数
- Tensorflow一些常用基本概念与函数(3)
- POSIX多线程——基本线程管理函数介绍
- Tensorflow一些常用基本概念与函数