前言

tensorflow官网给的例子用到了很多函数,然后并没有具体说明,还要自己去翻文档,有些函数是很常用的,下面来一一总结。

正文


一,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)可忽略

举例说明:

tensorflow
一个面向所有人的开源机器学习框架

# '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()求最大值等。

推荐内容
GitHub 加速计划 / te / tensorflow
28
4
下载
一个面向所有人的开源机器学习框架
最近提交(Master分支:2 个月前 )
4f64a3d5 Instead, check for this case in `ResolveUsers` and `ResolveOperand`, by querying whether the `fused_expression_root` is part of the `HloFusionAdaptor`. This prevents us from stepping into nested fusions. PiperOrigin-RevId: 724311958 2 个月前
aa7e952e Fix a bug in handling negative strides, and add a test case that exposes it. We can have negative strides that are not just -1, e.g. with a combining reshape. PiperOrigin-RevId: 724293790 2 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐