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 ...
随机推荐
- 进入一个jsp直接跳到另一个jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- Spring中使用构造函数实现Beans自动装配
以下内容引用自http://wiki.jikexueyuan.com/project/spring/beans-auto-wiring/spring-autowiring-by-Constructor ...
- DTRACE FOR MYSQL PHP
Using DTrace to troubleshoot Apache DTrace for MySQL , Inspecting MySQL with DTrace , MySQL DTrace P ...
- C++设计模式之适配器模式(二)
3.Socket网络通信的设计与实现------类适配器 除了对象适配器模式之外.适配器模式另一种形式.那就是类适配器模式,类适配器模式和对象适配器模式最大的差别在于适配器和适配者之间的关系不同,对象 ...
- 转: eclipse 快捷键列表(功能清晰版本)
转自: http://www.uml.org.cn/mobiledev/201110092.asp Eclipse 在开发中使用到的快捷键很实用噢 Ctrl+1 快速修复(最经典的快捷键,就不用多说了 ...
- linux用户列表
centos上面不知道添加了多少个账户,今天想清理一下,但是以前还未查看过linux用户列表, 一般情况下是 cat /etc/passwd 可以查看所有用户的列表 w 可以查看当前活跃的用户列表 c ...
- 用Lazarus编写第一个程序Pascal版的hello world
安装 Lazarus的过程不用多说,都是傻瓜式的. 打开Lazarus.Lazarus会自己主动新建一个窗体形式的应用程序. 你会看到五个窗体. 主窗体 这个窗体显示有标题栏.菜单条和工具栏. 对象视 ...
- vue 自定义报警组件
1.自定义报警组件 Alarm.vue <!-- 报警 组件 --> <template> <div class="alarm"> <!- ...
- 杭电1232畅通project
畅通project Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- performSelector调用和直接调用的区别
今天在准备出笔试题的过程中随便搜了一下其他的笔试题,看到其中一个就是关于performSelector与直接调用的区别. 个人感觉这其实是一个陷阱题,因为大部分应用场景下,用哪一种都可以,可以说是没有 ...