您的位置:首页 > 其它

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]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: