tf.reducemean()到底是什么意思?
https://blog.csdn.net/he_min/article/details/78694383
在tensorflow中经常见到reducemean这个api,到底有什么用,到底是对谁求均值?
api中是这样写的:
tf.reduce_mean(input_tensor, axis=None, keep_dims=False, name=None, reduction_indices=None)
- 1
Computes the mean of elements across dimensions of a tensor.
Reduces input_tensor along the dimensions given in axis. Unless keep_dims is true, the rank of the tensor is reduced by 1 for each entry in axis. If keep_dims is true, the reduced dimensions are retained with length 1.If axis has no entries, all dimensions are reduced, and a tensor with a single element is returned.
- 1
- 2
直观的翻译就是
根据给出的axis在input_tensor上求平均值。除非keep_dims为真,axis中的每个的张量秩会减少1。如果keep_dims为真,求平均值的维度的长度都会保持为1.如果不设置axis,所有维度上的元素都会被求平均值,并且只会返回一个只有一个元素的张量。
- 1
为了更加清楚的理解其含义,给出一个简单的例子:
import tensorflow as tf
import numpy as np
'''
x = [[1.,2.],[3.,4.]]
print(tf.reduce_mean(x))
print(tf.reduce_mean(x,0))
print(tf.reduce_mean(x,1))
'''
x = np.array([[1.,2.,3.],[4.,5.,6.]])
with tf.Session() as sess:
#返回所有元素的平均值
mean_none = sess.run(tf.reduce_mean(x))
#返回各列的平均值
mean_0 = sess.run(tf.reduce_mean(x, 0))
#返回各行的平均值向量
mean_1 = sess.run(tf.reduce_mean(x, 1))
print(x)
print(mean_none)
print(mean_0)
print(mean_1)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2015-09-06 对于System.Net.Http的学习(一)——System.Net.Http 简介
2015-09-06 一个共通的viewModel搞定所有的编辑页面-经典ERP录入页面(easyui + knockoutjs + mvc4.0)
2015-09-06 iBatisnet系列(二) 配置运行环境和日志处理
2015-09-06 IbatisNet的介绍和使用