tensorflow中tf.reduce_mean函数的使用
2020-04-20 07:04
549 查看
tf.reduce_mean 函数用于计算张量tensor沿着指定的数轴(tensor的某一维度)上的的平均值,主要用作降维或者计算tensor(图像)的平均值。
reduce_mean(input_tensor, axis=None, keep_dims=False, name=None, reduction_indices=None)
- 第一个参数input_tensor: 输入的待降维的tensor;
- 第二个参数axis: 指定的轴,如果不指定,则计算所有元素的均值;
- 第三个参数keep_dims:是否降维度,设置为True,输出的结果保持输入tensor的形状,设置为False,输出结果会降低维度;
- 第四个参数name: 操作的名称;
- 第五个参数 reduction_indices:在以前版本中用来指定轴,已弃用;
以一个维度是2,形状是[2,3]的tensor举例:
import tensorflow as tf x = [[1,2,3], [1,2,3]] xx = tf.cast(x,tf.float32) mean_all = tf.reduce_mean(xx, keep_dims=False) mean_0 = tf.reduce_mean(xx, axis=0, keep_dims=False) mean_1 = tf.reduce_mean(xx, axis=1, keep_dims=False) with tf.Session() as sess: m_a,m_0,m_1 = sess.run([mean_all, mean_0, mean_1]) print m_a # output: 2.0 print m_0 # output: [ 1. 2. 3.] print m_1 #output: [ 2. 2.]
如果设置保持原来的张量的维度,keep_dims=True ,结果:
print m_a # output: [[ 2.]] print m_0 # output: [[ 1. 2. 3.]] print m_1 #output: [[ 2.], [ 2.]]
类似函数还有:
- tf.reduce_sum :计算tensor指定轴方向上的所有元素的累加和;
- tf.reduce_max : 计算tensor指定轴方向上的各个元素的最大值;
- tf.reduce_all : 计算tensor指定轴方向上的各个元素的逻辑和(and运算);
- tf.reduce_any: 计算tensor指定轴方向上的各个元素的逻辑或(or运算);
到此这篇关于tensorflow中tf.reduce_mean函数的使用的文章就介绍到这了,更多相关tensorflow tf.reduce_mean内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:
- 关于Tensorflow中的tf.train.batch函数的使用
- TensorFlow入门使用 tf.train.Saver()保存模型
- tensorflow之变量初始化(tf.Variable)使用详解
- Tensorflow 利用tf.contrib.learn建立输入函数的方法
- Tensorflow中tf.ConfigProto()的用法详解
- tensorflow中tf.slice和tf.gather切片函数的使用
- TensorFlow tf.nn.max_pool实现池化操作方式
- 浅谈tensorflow 中tf.concat()的使用
- tensorflow tf.train.batch之数据批量读取方式
- TensorFlow tf.nn.conv2d实现卷积的方式
相关文章推荐
- tensorflow中 tf.equal、tf.cast、tf.reduce_mean函数使用
- matlab2c使用c++实现matlab函数系列教程-mean函数
- 数据库技术之PowerDesigner使用
- json解析:fastjson 使用
- 在liferay中如何使用Ajax的请求
- 【总结 】WebView的使用
- git stash使用 笔记
- Git使用
- android AudioRecord 与 AudioTrack的录音加回放的使用
- 如何在命令行中使用 ftp 命令上传和下载文件
- C语言可变参数函数的使用方法讲解
- Retrofit 和 RxJava 结合使用
- iOS 使用Method Swizzling隐藏Status Bar
- Android Design Support Library控件使用总结(一)
- CountDownLatch使用
- 安卓图片加载之使用universalimageloader加载圆形圆角图片
- Node.js的Express框架使用上手指南
- Android访问网络,使用HttpURLConnection还是HttpClient?
- yii使用网页
- 使用ChemDraw Std 14如何绘制曲线