Reduction operations
Reuction operations
Reduction operations
A reduction operations on a tensor is an operation that reduces the number of elements contained within the tensor.
Tensors give us the ability to manage out data. Reduction operations allow us to perform operations on elements within a single tensor.
Suppose we have the following 3$\times$3 rank-2 tensor.
> t = torch.tensor([
[0, 1, 0],
[2, 0, 2],
[0, 3, 0]
], dtype=torch.float32)
Common tensor reduction operations
> t.sum()
tensor(8.)
> t.numel()
9
> t.prod()
tensor(0.)
> t.mean()
tensor(.8889)
> t.std()
tensor(1.1667)
Reducing tensors by axes
Suppose we have the following tensor:
> t = torch.tensor([
[1,1,1,1],
[2,2,2,2],
[3,3,3,3]
], dtype=torch.float32)
This time , we will specify a dimension to reduce.
> t.sum(dim=0)
tensor([6., 6., 6., 6.])
> t.sum(dim=1)
tensor([4., 8., 12.])
Argmax tensor reduction operation
Argmax returns the index location of the maximum value inside a tensor.
t = torch.tensor([
[1,0,0,2],
[0,3,3,0],
[4,0,0,5]
], dtype=torch.float32)
If we don't specific an axis to the argmax() method, it returns the index location of the max value from the flattened tensor, which in the case is indeed 11.
> t.max()
tensor(5.)
> t.argmax()
tensor(11)
> t.flatten()
tensor([1., 0., 0., 2., 0., 3., 3., 0., 4., 0., 0., 5.])
Work with specific axis now:
> t.max(dim=0)
(tensor([4., 3., 3., 5.]), tensor([2, 1, 1, 2]))
> t.argmax(dim=0)
tensor([2, 1, 1, 2])
> t.max(dim=1)
(tensor([2., 3., 5.]), tensor([3, 1, 3]))
> t.argmax(dim=1)
tensor([3, 1, 3])
In practice, we often use the argmax() function on a network's output prediction tensor, to determine which category has the highest prediction value.
Reduction operations的更多相关文章
- Java8初体验(二)Stream语法详解
感谢同事[天锦]的投稿.投稿请联系 tengfei@ifeve.com 上篇文章Java8初体验(一)lambda表达式语法比 较详细的介绍了lambda表达式的方方面面,细心的读者会发现那篇文章的例 ...
- (转)分布式深度学习系统构建 简介 Distributed Deep Learning
HOME ABOUT CONTACT SUBSCRIBE VIA RSS DEEP LEARNING FOR ENTERPRISE Distributed Deep Learning, Part ...
- atitit. 集合groupby 的实现(2)---自定义linq查询--java .net php
atitit. 集合groupby 的实现(2)---自定义linq查询--java .net php 实现方式有如下 1. Linq的实现原理流程(ati总结) 1 2. groupby 与 事 ...
- Java8 如何进行stream reduce,collection操作
Java8 如何进行stream reduce,collection操作 2014-07-16 16:42 佚名 oschina 字号:T | T 在java8 JDK包含许多聚合操作(如平均值,总和 ...
- OpenMP初步(英文)
Beginning OpenMP OpenMP provides a straight-forward interface to write software that can use multipl ...
- Stream语法详解
1. Stream初体验 我们先来看看Java里面是怎么定义Stream的: A sequence of elements supporting sequential and parallel agg ...
- Lambdas in Java 8--reference
Part 1 reference:http://jaxenter.com/lambdas-in-java-8-part-1-49700.html Get to know lambda expressi ...
- JDK1.8聚合操作
在java8 JDK包含许多聚合操作(如平均值,总和,最小,最大,和计数),返回一个计算流stream的聚合结果.这些聚合操作被称为聚合操作.JDK除返回单个值的聚合操作外,还有很多聚合操作返回一个c ...
- 关于并行计算的Scan操作
simple and common parallel algorithm building block is the all-prefix-sums operation. In this chapte ...
随机推荐
- linux下启动mysql服务(类似于windows下net start mysql)
1.linux系统启动方式:service mysql start.其类似于windows下net start mysql
- weblogic线程阻塞性能调优(图解)
转自:http://blog.csdn.net/z69183787/article/details/12647539 声明:出现这个问题有程序方面.网络方面.weblogic设置方面等等原因,此文章主 ...
- Windows下SVN服务器及客户端的使用
原文地址:windows下配置VisualSVN Server服务器 作者:Deem_passion 下载安装文件: 服务端安装文件:VisualSVN-Server-1.6.2 客户端安装文件:To ...
- Office WORD WPS如何设置PPT播放全屏
1 在设计-页面设置中,幻灯片大小改成自定义,高度和宽度如下图所示.(我个人的笔记本是15.6存的宽屏笔记本,你可以根据自己笔记本的比例修改宽度和高度的数据来或者不同的比例值),注意在HDMI的输出方 ...
- [转] When to use what language and why
Published by Seraphimsan Oct 13, 2010 (last update: Oct 14, 2010) When to use what language and why ...
- Java SE之break和continue标签
文是学习网络上的文章时的总结,感谢大家无私的分享. Java没有提供goto功能,可是保留了gotokeyword. 在java中能够使用break标签和continue标签功能实现简版的goto功能 ...
- 【CTF】后续深入学习内容
1.i春秋 https://www.ichunqiu.com/course/451 搜索black hat,可以看到黑帽大会的内容.免费. 2.wireshark 基础篇 1)由于Wireshark是 ...
- oracle sql 超长报ORA-01460错误
程序查找数据的时候报错了: ORA-01460: 转换请求无法实施或不合理 这是什么鬼?不合理你就提嘛,报错干什么. 程序原本好好的,现在突然报错了.数据库并没有什么更改. 后来猜测是因为执行的SQL ...
- 自己写的Android端HttpUtil工具类
package com.sxt.jcjd.util; import java.io.IOException; import java.io.UnsupportedEncodingException; ...
- Hibernate中Criteria的完整用法?
http://www.cnblogs.com/mabaishui/archive/2009/10/16/1584510.html