我是靠谱客的博主 野性大门,这篇文章主要介绍tensorflow函数总结,现在分享给大家,希望可以做个参考。

数值乘法mul

例如:a=3,b=3,a*b = 9

复制代码
1
2
3
4
5
6
import 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}))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

结果:9.0

数值和add

例如: a = 3, b=3 ,a+b = 6

复制代码
1
2
3
4
5
6
import 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}))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

结果:6.0

数值减法sub

例如:a=3,b=3,a-b = 0

复制代码
1
2
3
4
5
6
import 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}))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

结果: 0.0

数值除法div

例如: a=3,b=3,a/b = 1.0

复制代码
1
2
3
4
5
6
import 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
  • 2
  • 3
  • 4
  • 5
  • 6

结果: 1.0

数值取模mod

例如:a=3,b=3,a mod b = 0

复制代码
1
2
3
4
5
6
import 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}))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

结果: 0.0

数值绝对值abs

例如:a=-3, abs (a) = 3

复制代码
1
2
3
4
5
6
import 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}))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

结果: 3.0

数值非负值neg

例如:a=-3, neg (a) = 3

复制代码
1
2
3
4
5
import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.neg(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3}))
  • 1
  • 2
  • 3
  • 4
  • 5

结果: 3.0

数值符号函数sign

例如:a=-3, neg (a) = 3

复制代码
1
2
3
4
5
import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.neg(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3}))
  • 1
  • 2
  • 3
  • 4
  • 5

结果: 3.0

数值符号函数sign

例如: a=-3,sign(a) = -1

复制代码
1
2
3
4
5
import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.sign(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3}))
  • 1
  • 2
  • 3
  • 4
  • 5

结果: -1.0

数值倒数inv

例如: a=-3,sign(a) = -1

复制代码
1
2
3
4
5
import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.sign(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3}))
  • 1
  • 2
  • 3
  • 4
  • 5

结果: -1.0

数值平方square

例如: a=-3,square(a) = 9

复制代码
1
2
3
4
5
import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.square(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3}))
  • 1
  • 2
  • 3
  • 4
  • 5

结果: 9.0

数值最近的整数round

例如: a=-3.6,round(a) = -4.0

复制代码
1
2
3
4
import tensorflow as tf y = tf.round(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3.6}))
  • 1
  • 2
  • 3
  • 4

结果: -4.0

例如: a=-3.3,round(a) = -3.0

复制代码
1
2
3
4
import tensorflow as tf y = tf.round(a) sess = tf.Session() print (sess.run(y, feed_dict={a: -3.3}))
  • 1
  • 2
  • 3
  • 4

结果:-3.0

数值平方根sqrt

例如: a=4,sqrt(a) = 2

复制代码
1
2
3
4
5
import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.sqrt(a) sess = tf.Session() print (sess.run(y, feed_dict={a: 4}))
  • 1
  • 2
  • 3
  • 4
  • 5

结果: 2.0

数值幂次pow

例如: a=2,b=3,pow(a,b) = 8

复制代码
1
2
3
4
5
6
import 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}))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

结果: 8.0

数值最近的整数exp

例如: a=2,exp(a) = 7.38906

复制代码
1
2
3
4
5
import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.exp(a) sess = tf.Session() print (sess.run(y, feed_dict={a: 2}))
  • 1
  • 2
  • 3
  • 4
  • 5

结果: 7.38906

数值取对数log

例如: a=-3.6,round(a) = -4.0

复制代码
1
2
3
4
5
import tensorflow as tf a = tf.placeholder(tf.float32) y = tf.log(a) sess = tf.Session() print (sess.run(y, feed_dict={a: 2}))
  • 1
  • 2
  • 3
  • 4
  • 5

结果: 0.69314718056

数值取最大值maximum

例如: a=-3.6, b = 2,maximum(a,b)=2

复制代码
1
2
3
4
5
6
import 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}))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

结果: 2.0

数值最小值minimum

例如: a=2,b=3minimum(a) = 3

复制代码
1
2
3
4
5
6
import 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}))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

结果: 2.0

数值余弦函数cos

例如: a=2,cos(a) = -0.416146836547

复制代码
1
2
3
4
5
import tensorflow as tf a = tf.placeholder(tf.float64) y = tf.cos(a) sess = tf.Session() print (sess.run(y, feed_dict={a: 2}))
  • 1
  • 2
  • 3
  • 4
  • 5

结果: -0.416146836547

数值正弦函数sin

例如: a=2,sin(a) = -0.416146836547

复制代码
1
2
3
4
5
import tensorflow as tf a = tf.placeholder(tf.float64) y = tf.sin(a) sess = tf.Session() print (sess.run(y, feed_dict={a: 2}))
  • 1
  • 2
  • 3
  • 4
  • 5

结果: 0.909297426826

最后

以上就是野性大门最近收集整理的关于tensorflow函数总结的全部内容,更多相关tensorflow函数总结内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部