Tensorflow数学运算

±*/
**,tf.pow,tf.square
sqrt
//,%
tf.exp,tf.log
@,tf.matmul 矩阵相乘
linear layer
reduce_mean/max/min/sum
tf.math.log()等价于loge()
在这里插入图片描述

b=tf.fill([2,2],2.)
a=tf.ones([2,2])
a+b,a-b,a*b,a/b
(<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[3., 3.],
       [3., 3.]], dtype=float32)>, <tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[-1., -1.],
       [-1., -1.]], dtype=float32)>, <tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[2., 2.],
       [2., 2.]], dtype=float32)>, <tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[0.5, 0.5],
       [0.5, 0.5]], dtype=float32)>)
a//b,a%b
(<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[0., 0.],
       [0., 0.]], dtype=float32)>, <tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[1., 1.],
       [1., 1.]], dtype=float32)>)
tf.math.log(a)
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[0., 0.],
       [0., 0.]], dtype=float32)>

tf.exp(a)
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[2.7182817, 2.7182817],
       [2.7182817, 2.7182817]], dtype=float32)>
tf.math.log(8.)/tf.math.log(2.)
tf.math.log(100.)/tf.math.log(10.)
c=tf.pow(b,3)
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[8., 8.],
       [8., 8.]], dtype=float32)>
tf.square(c)
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[64., 64.],
       [64., 64.]], dtype=float32)>
a=tf.ones([4,2,3])
b=tf.fill([4,3,5],2.)
a@b
tf.matmul(a,b)
<tf.Tensor: shape=(4, 2, 5), dtype=float32, numpy=
array([[[6., 6., 6., 6., 6.],
        [6., 6., 6., 6., 6.]],
       [[6., 6., 6., 6., 6.],
        [6., 6., 6., 6., 6.]],
       [[6., 6., 6., 6., 6.],
        [6., 6., 6., 6., 6.]],
       [[6., 6., 6., 6., 6.],
        [6., 6., 6., 6., 6.]]], dtype=float32)>
x=tf.ones([4,2])
w=tf.ones([2,1])
b=tf.constant(0.1)
x@w+b
<tf.Tensor: shape=(4, 1), dtype=float32, numpy=
array([[2.1],
       [2.1],
       [2.1],
       [2.1]], dtype=float32)>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值