TensorFlow学习笔记(十九) 基本算术运算和Reduction归约计算
2017-08-17 13:45
267 查看
基本运算,变量由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]
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]
相关文章推荐
- shell基本计算、逻辑运算、位运算详解
- Matlab与科学计算的基本运算
- Mohican_4/1 C语言 移位运算基本操作 计算二进制的个数
- shell 基本计算、逻辑运算、位运算详解
- 数字图像处理—算术运算基本作用及模板(样板,窗口,滤波器)运算
- Tenosrflow中基本算术运算函数
- java中的栈Stack的基本使用和应用(二) ——利用栈计算合法的算术表达,中缀表达式转后缀表达式
- shell基本计算、逻辑运算、位运算详解
- python -- numpy 基本数据类型,算术运算,组合,分割 函数
- shell 基本计算、逻辑运算、位运算详解
- Tensorflow学习笔记(2)-基本运算
- 算术运算2(逻辑计算和复合运算)
- 算术基本运算
- 线性表的基本运算及多项式的算术运算
- Shell基本编程之条件、迭代流程控制、算术运算
- shell 基本计算、逻辑运算、位运算详解
- 计算几何学习笔记之基本运算
- shell 基本计算、逻辑运算、位运算详解
- ACM计算几何模板——二维几何基础(基本运算,点和线,多边形)
- 基本算术计算的方法(搜狗面试题之一)