您的位置:首页 > 编程语言 > Python开发

python之tf.reduce语句mean()max()

2018-01-24 20:24 393 查看
一,tensorflow中有一类在tensor的某一维度上求值的函数。如:

求最大值tf.reduce_max(input_tensor, reduction_indices=None, keep_dims=False, name=None)

求平均值tf.reduce_mean(input_tensor, reduction_indices=None, keep_dims=False, name=None)

参数1--input_tensor:待求值的tensor。

参数2--reduction_indices:在哪一维上求解。

参数(3)(4)可忽略

举例说明:

# 'x' is [[1., 2.]# [3., 4.]]


x是一个2维数组,分别调用reduce_*函数如下:

首先求平均值:

tf.reduce_mean(x) ==> 2.5 #如果不指定第二个参数,那么就在所有的元素中取平均值tf.reduce_mean(x, 0) ==> [2., 3.] #指定第二个参数为0,则第一维的元素取平均值,即每一列求平均值tf.reduce_mean(x, 1) ==> [1.5, 3.5] #
指定第二个参数为1,则第二维的元素取平均值,即每一行求平均值

同理,还可用tf.reduce_max()求最大值等。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python tf