TensorFlow学习笔记(十九) 基本算术运算和Reduction归约计算
基本運算,變量由tf.constant函數轉化為1階張量。然后計算;現在用tf.reduce_prod()和tf.reduce_sum()函數重新定義,當給定某個tensor張量作為輸入時,這些函數會接收其所有分量,然后分別將它們相乘或相加。
1. 基本算術運算
tf.add(x, y, name=None)
求和
tf.sub(x, y, name=None)
減法
tf.multiply(x, y, name=None)
乘法
tf.div(x, y, name=None)
除法
tf.mod(x, y, name=None)
取模
tf.abs(x, name=None)
求絕對值
tf.neg(x, name=None)
取負 (y = -x).
tf.sign(x, name=None)
返回符號 y = sign(x) = -1 if x < 0; 0 if x == 0; 1 if x > 0.
tf.inv(x, name=None)
取反
tf.square(x, name=None)
計算平方 (y = x * x = x^2).
tf.round(x, name=None)
舍入最接近的整數 # ‘a’ is [0.9, 2.5, 2.3, -4.4] tf.round(a) ==> [ 1.0, 3.0, 2.0, -4.0 ]
tf.sqrt(x, name=None)
開根號 (y = \sqrt{x} = x^{1/2}).
tf.pow(x, y, name=None)
冪次方 # tensor ‘x’ is [[2, 2], [3, 3]] # tensor ‘y’ is [[8, 16], [2, 3]] tf.pow(x, y) ==> [[256, 65536], [9, 27]]
tf.exp(x, name=None)
計算e的次方
tf.log(x, name=None)
計算log,一個輸入計算e的ln,兩輸入以第二輸入為底
tf.maximum(x, y, name=None)
返回最大值 (x > y ? x : y)
tf.minimum(x, y, name=None)
返回最小值 (x < y ? x : y)
tf.cos(x, name=None)
三角函數cosine
tf.sin(x, name=None)
三角函數sine
tf.tan(x, name=None)
三角函數tan
tf.atan(x, name=None)
三角函數ctan
2. 歸約計算(Reduction)
tf.reduce_sum(input_tensor, reduction_indices=None, keep_dims=False, name=None)
計算輸入tensor元素的和,或者安照reduction_indices指定的軸進行求和 # ‘x’ is [[1, 1, 1]
# [1, 1, 1]] tf.reduce_sum(x) ==> 6 tf.reduce_sum(x, 0) ==> [2, 2, 2] tf.reduce_sum(x, 1) ==> [3, 3] tf.reduce_sum(x, 1, keep_dims=True) ==> [[3], [3]] tf.reduce_sum(x, [0, 1]) ==> 6
tf.reduce_prod(input_tensor, reduction_indices=None, keep_dims=False, name=None)
計算輸入tensor元素的乘積,或者安照reduction_indices指定的軸進行求乘積
tf.reduce_min(input_tensor, reduction_indices=None, keep_dims=False, name=None)
求tensor中最小值
tf.reduce_max(input_tensor, reduction_indices=None, keep_dims=False, name=None)
求tensor中最大值
tf.reduce_mean(input_tensor, reduction_indices=None, keep_dims=False, name=None)
求tensor中平均值
tf.reduce_all(input_tensor, reduction_indices=None, keep_dims=False, name=None)
對tensor中各個元素求邏輯’與’ # ‘x’ is # [[True, True] # [False, False]] tf.reduce_all(x) ==> False tf.reduce_all(x, 0) ==> [False, False] tf.reduce_all(x, 1) ==> [True, False]
tf.reduce_any(input_tensor, reduction_indices=None, keep_dims=False, name=None)
對tensor中各個元素求邏輯’或’
tf.accumulate_n(inputs, shape=None, tensor_dtype=None, name=None)
計算一系列tensor的和 # tensor ‘a’ is [[1, 2], [3, 4]] # tensor b is [[5, 0], [0, 6]] tf.accumulate_n([a, b, a]) ==> [[7, 4], [6, 14]]
tf.cumsum(x, axis=0, exclusive=False, reverse=False, name=None)
求累積和 tf.cumsum([a, b, c]) ==> [a, a + b, a + b + c] tf.cumsum([a, b, c], exclusive=True) ==> [0, a, a + b] tf.cumsum([a, b, c], reverse=True) ==> [a + b + c, b + c, c] tf.cumsum([a, b, c], exclusive=True, reverse=True) ==> [b + c, c, 0]
總結
以上是生活随笔為你收集整理的TensorFlow学习笔记(十九) 基本算术运算和Reduction归约计算的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TensorFlow学习笔记(十八)tf
- 下一篇: TensorFlow学习笔记(二十) t