【CNN记录】tensorflow中reduceMax、reduceMin、reduceSum、reduceMean介绍
admin
2024-02-05 17:35:06
0

reduceSum 

tf.reduce_sum(
    input_tensor, axis=None, keepdims=False, name=None
)

说明:在指定维度上求多维tensor元素之和,并且按照axis消除该维度,除非keepdims为True

input_tensor:输入张量

axis:需要降维的维度

keepdims:是否保留维度

name:操作数的名字(可选)

举个栗子

>a = np.random.random_integers(3,size=(2,3,4))
>input = tf.constant(a)
tf.Tensor(
[[[2 3 1 1][1 1 2 2][1 2 2 1]][[1 2 1 2][2 2 3 3][3 1 3 3]]], shape=(2, 3, 4), dtype=int32)>output = tf.reduce_sum(input);
tf.Tensor(45, shape=(), dtype=int32)#axis为None的时候,所有维度都会被降维(展成一维加起来),所有元素加起来为45>output = tf.reduce_sum(input,axis=0)
tf.Tensor(
[[3 5 2 3][3 3 5 5][4 3 5 4]], shape=(3, 4), dtype=int32)#axis=0时,最外的维度相加,这里就是2+1、3+2、1+1、1+2 ...,最终得到一个(3,4)的张量如果keepdims=True
>output = tf.reduce_sum(input,axis=0,keepdims=True)
tf.Tensor(
[[[3 5 2 3][3 3 5 5][4 3 5 4]]], shape=(1, 3, 4), dtype=int32)#保留了axis指定的维度,(2,3,4)变成(1,3,4)>output = tf.reduce_sum(input,axis=1);
tf.Tensor(
[[4 6 5 4][6 5 7 8]], shape=(2, 4), dtype=int32)#axis=1时,dim1维度相加,这里就是2+1+1、3+1+2、1+2+2、1+2+1 ...,最终得到一个(2,4)的张量

reduceMax

tf.reduce_max(
    input_tensor, axis=None, keepdims=False, name=None
)

参数说明参考reducesum 

继续举个栗子

>a = np.random.random_integers(3,size=(2,3,4)) #创建一个固定dim的numpy
>input = tf.constant(a)
tf.Tensor(
[[[2 3 1 2][3 2 2 1][2 1 1 1]][[2 3 3 2][3 1 3 1][1 1 2 1]]], shape=(2, 3, 4), dtype=int32)>output = tf.reduce_max(input)
tf.Tensor(3, shape=(), dtype=int32)#axis为None时取所有元素最大值>output = tf.reduce_max(input,axis=0)
tf.Tensor(
[[2 3 3 2][3 2 3 1][2 1 2 1]], shape=(3, 4), dtype=int32)#axis=0的时候,按照dim0取最大值,即:max(2,2)、max(3,3)、max(1,3)、max(2,2)。。。
#最终得到一个(3,4)的tensor

reduceMin

tf.reduce_min(
    input_tensor, axis=None, keepdims=False, name=None
)

说明:同reduceMax,只是取最小值

 reduceMean

说明:指定axis代表的维度求均值,并且按照axis消除该维度,除非keepdims为True

>input = tf.constant([[1., 1.], [2., 2.]])
>output = tf.reduce_mean(input)
tf.Tensor(1.5, shape=(), dtype=float32)#所有元素求均值>output = tf.reduce_mean(input, 0)
tf.Tensor([1.5 1.5], shape=(2,), dtype=float32)#dim0维度求均值,即计算[1,2]、[1,2]均值为1.5、1.5>output = tf.reduce_mean(input, 1)
tf.Tensor([1. 2.], shape=(2,), dtype=float32)#dim0维度求均值,即计算[1,1]、[2,2]均值为1.、2.

其实这些都差不多,包括argmin、argmax

相关内容

热门资讯

【MySQL】锁 锁 文章目录锁全局锁表级锁表锁元数据锁(MDL)意向锁AUTO-INC锁...
【内网安全】 隧道搭建穿透上线... 文章目录内网穿透-Ngrok-入门-上线1、服务端配置:2、客户端连接服务端ÿ...
GCN的几种模型复现笔记 引言 本篇笔记紧接上文,主要是上一篇看写了快2w字,再去接入代码感觉有点...
数据分页展示逻辑 import java.util.Arrays;import java.util.List;impo...
Redis为什么选择单线程?R... 目录专栏导读一、Redis版本迭代二、Redis4.0之前为什么一直采用单线程?三、R...
【已解决】ERROR: Cou... 正确指令: pip install pyyaml
关于测试,我发现了哪些新大陆 关于测试 平常也只是听说过一些关于测试的术语,但并没有使用过测试工具。偶然看到编程老师...
Lock 接口解读 前置知识点Synchronized synchronized 是 Java 中的关键字,...
Win7 专业版安装中文包、汉... 参考资料:http://www.metsky.com/archives/350.htm...
3 ROS1通讯编程提高(1) 3 ROS1通讯编程提高3.1 使用VS Code编译ROS13.1.1 VS Code的安装和配置...
大模型未来趋势 大模型是人工智能领域的重要发展趋势之一,未来有着广阔的应用前景和发展空间。以下是大模型未来的趋势和展...
python实战应用讲解-【n... 目录 如何在Python中计算残余的平方和 方法1:使用其Base公式 方法2:使用statsmod...
学习u-boot 需要了解的m... 一、常用函数 1. origin 函数 origin 函数的返回值就是变量来源。使用格式如下...
常用python爬虫库介绍与简... 通用 urllib -网络库(stdlib)。 requests -网络库。 grab – 网络库&...
药品批准文号查询|药融云-中国... 药品批文是国家食品药品监督管理局(NMPA)对药品的审评和批准的证明文件...
【2023-03-22】SRS... 【2023-03-22】SRS推流搭配FFmpeg实现目标检测 说明: 外侧测试使用SRS播放器测...
有限元三角形单元的等效节点力 文章目录前言一、重新复习一下有限元三角形单元的理论1、三角形单元的形函数(Nÿ...
初级算法-哈希表 主要记录算法和数据结构学习笔记,新的一年更上一层楼! 初级算法-哈希表...
进程间通信【Linux】 1. 进程间通信 1.1 什么是进程间通信 在 Linux 系统中,进程间通信...
【Docker】P3 Dock... Docker数据卷、宿主机与挂载数据卷的概念及作用挂载宿主机配置数据卷挂载操作示例一个容器挂载多个目...