博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tf.reducemean()到底是什么意思?
阅读量:6949 次
发布时间:2019-06-27

本文共 1223 字,大约阅读时间需要 4 分钟。

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)
你可能感兴趣的文章
OSChina 周三乱弹 ——你最想在墓碑上被写些什么
查看>>
openjdk 7编译记录
查看>>
数据结构 ConcurrentHashMap
查看>>
spring boot 初始化是怎么扫描类的
查看>>
css3实现圆形进度条
查看>>
C++学习需要看的书籍
查看>>
jQuery的常用方法
查看>>
mysql联查时为空补全和jdbc获取最后插入生成的id
查看>>
[Android] ArcFace人脸识别 Demo
查看>>
人脸识别 闸机开发分享
查看>>
iOS开发 怎么适配iOS9
查看>>
Jquery选择器性能发现
查看>>
iptables从入门到应用
查看>>
WindowsAPI详解——TerminateProcess 终止|杀死其它进程
查看>>
java入门:dos命令运行java文件
查看>>
MySQL基本知识点
查看>>
自动加入域脚本
查看>>
黑莓10应用多源自Android
查看>>
创建Oracle表空间
查看>>
vm,vbox 虚拟机设置开机自动启动(创建虚拟机快捷方式的命令)
查看>>