码迷,mamicode.com
首页 > 其他好文 > 详细

吴裕雄--天生自然TensorFlow2教程:数学运算

时间:2019-12-31 14:11:50      阅读:56      评论:0      收藏:0      [点我收藏+]

标签:exp   batch   out   col   cas   数学   数学运算   a+b   ant   

import tensorflow as tf

b = tf.fill([2, 2], 2.)
a = tf.ones([2, 2])
a+b
a-b
a*b
a/b
b // a
b % a
tf.math.log(a)  # 只有以e为底的log
tf.exp(a)
tf.math.log(8.)/tf.math.log(2.)  # 以2为底
tf.math.log(100.)/tf.math.log(10.)  # 以10为底
tf.pow(b, 3)
b**3
tf.sqrt(b)
a@b
tf.matmul(a, b)
a = tf.ones([4, 2, 3])  # 4作为batch处理
b = tf.fill([4, 3, 5], 2.)  # 4作为batch处理
a@b
tf.matmul(a, b)
bb = tf.broadcast_to(b, [4, 3, 5])
a@bb
x = tf.ones([4, 2])
W = tf.ones([2, 1])
b = tf.constant(0.1)  # 自动broadcast为[4,1]

x@W + b
out = x@W + b
tf.nn.relu(out)

 

吴裕雄--天生自然TensorFlow2教程:数学运算

标签:exp   batch   out   col   cas   数学   数学运算   a+b   ant   

原文地址:https://www.cnblogs.com/tszr/p/12124045.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!