当前位置:网站首页>Shengxin experiment record (part2)--tf.reduce_sum() usage introduction
Shengxin experiment record (part2)--tf.reduce_sum() usage introduction
2022-08-11 01:40:00 【GoatGui】
学习笔记,仅供参考,有错必纠
参考自:tf.reduce_sum()用法介绍
前言
I came across this function while reproducing…emmm… Speaking of which, I really know very little about deep learning.
方法定义
tf.reduce_sum()
The role of is to calculate the sum of the elements in the tensor in a certain way.
tf.reduce_sum(
input_tensor,
axis=None,
keepdims=None,
name=None)
参数解释:
input_tensoris the tensor to be processed.
axisSpecifies which dimension to sum by,All elements are added by default.
keepdimsIndicates that the dimensions of the original tensor are not maintained,默认为False,若为TrueThe original tensor dimensions are maintained, .
nameUsed to define the operation name.
示例
有形如(2,3,4)的三维张量:
import tensorflow as tf
a = tf.constant([[[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 9, 8]],
[[7, 6, 5, 4],
[3, 2, 1, 0],
[1, 2, 3, 4]]])
print(a.shape)
# (2, 3, 4)
分别设置axis为0,1,2The result of performing the addition is as follows:
b = tf.reduce_sum(a, axis = 0)
c = tf.reduce_sum(a, axis = 1)
d = tf.reduce_sum(a, axis = 2)
sess = tf.InteractiveSession()
b
b.eval()
<tf.Tensor 'Sum_18:0' shape=(3, 4) dtype=int32>
array([[ 8, 8, 8, 8],
[ 8, 8, 8, 8],
[10, 12, 12, 12]])
c
c.eval()
<tf.Tensor 'Sum_19:0' shape=(2, 4) dtype=int32>
array([[15, 18, 19, 20],
[11, 10, 9, 8]])
d
d.eval()
<tf.Tensor 'Sum_20:0' shape=(2, 3) dtype=int32>
array([[10, 26, 36],
[22, 6, 10]])
可以看到,The original tensor is three-dimensional,指定axis
进行一次tf.reduce_sum()
Then it becomes a two-dimensional tensor. 如果设置keepdims=True
,则结果如下,It can be seen that the tensor after calculating the sum is still three-dimensional,其中指定axisThe number of elements in that dimension is 1,The other dimensions remain unchanged.
b = tf.reduce_sum(a, axis = 0, keepdims=True)
c = tf.reduce_sum(a, axis = 1, keepdims=True)
d = tf.reduce_sum(a, axis = 2, keepdims=True)
b
b.eval()
<tf.Tensor 'Sum_24:0' shape=(1, 3, 4) dtype=int32>
array([[[ 8, 8, 8, 8],
[ 8, 8, 8, 8],
[10, 12, 12, 12]]])
c
c.eval()
<tf.Tensor 'Sum_25:0' shape=(2, 1, 4) dtype=int32>
array([[[15, 18, 19, 20]],
[[11, 10, 9, 8]]])
d
d.eval()
<tf.Tensor 'Sum_26:0' shape=(2, 3, 1) dtype=int32>
array([[[10],
[26],
[36]],
[[22],
[ 6],
[10]]])
sess.close()
边栏推荐
- Sigma开发注意细节
- Single-chip human-computer interaction--matrix key
- 【HFSS学习记录2】腔体滤波器的设计与仿真
- 进程间通信方式(1)无名管道(全CSDN最用心的博主)
- [GXYCTF2019]BabySQli
- The latest domestic power supply manufacturers and pin-to-pin replacement manuals for specific models are released
- 络达开发---UI定义+自定义按钮事件
- FPGA学习专栏-串口通信(xinlinx)
- Qt 中的隐式共享
- 络达开发---自定义BLE服务(二):功能实现
猜你喜欢
如何防止离职员工把企业文件拷贝带走?法律+技术,4步走
apache+PHP+MySQL+word press,安装word press时页面报错?
数据库数据采集利器FlinkCDC
Apache Commons Configuration远程代码执行漏洞(CVE-2022-33980)分析&复现
数据分析面试手册《统计篇》
postgresql参数意义
双机热备综合实验(VRRP+OSPF+VTP+NAT+DHCP+PVSTP+单臂路由)
sed of the Three Musketeers of Shell Programming
二维数组实战项目--------《扫雷游戏》
Update chromedriver driver programming skills │ selenium
随机推荐
#yyds Dry Goods Inventory#[Yugong Series] August 2022 Go Teaching Course 008-Integer of Data Types
dump_stack()
【iframe父页面调用子页面的方法】踩坑:获取元素的时候需要用 `[x]`是关键,不能用`.eq(x)`否则获取不到。
总结Qt中常用文件信息QFileInfo的获取:后缀,名称,路径,链接
两日总结九
数据分析面试手册《SQL篇》
还在用 Xshell?你 out 了,推荐一个更现代的终端连接工具,好用到爆!
Successfully resolved raise TypeError('Unexpected feature_names type')TypeError: Unexpected feature_names type
单片机人机交互--矩阵按键
WinForm (5) control and its members
嵌入式软件打log的一些心得
15 DOM 扩展
How to determine the size of the version number
More parameter exposure of Pico 4: Pancake + color perspective, and Pro version
uni-app实现app和H5调用手机拨号功能
Still using Xshell?You are out, recommend a more modern terminal connection tool, easy to use!
[GXYCTF2019]BabySQli
【开源】壁纸软件,给自己电脑设计专属特效
SystemVerilog: 验证知识点点滴滴
OpenWrt之opkg详解