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 ...
随机推荐
- Python高级进阶(二)Python框架之Django写图书管理系统(LMS)
正式写项目准备前的工作 Django是一个Web框架,我们使用它就是因为它能够把前后端解耦合而且能够与数据库建立ORM,这样,一个Python开发工程师只需要干自己开发的事情就可以了,而在使用之前就我 ...
- Nginx配置upstream实现负载均衡及keepalived实现nginx高可用
(原文链接:http://www.studyshare.cn/blog-front//blog/details/1159/0 ) 一.准备工作 1.准备两个项目,发布到不同的服务器上,此处使用2个虚拟 ...
- 全新开始fighting
a.python准备工作 Python种类: JPython IronPython JavaScriptPython RubyPython CPython ********** ...
- HTML DOM对象的属性和方法介绍(原生JS方法)
HTML DOM对象的属性和方法介绍 DOM 是 Document Object Model(文档对象模型)的缩写. DOM(文档对象模型)是针对HTML和XML文档的一个API(应用程序编程接口), ...
- java自动识别用户上传的文本文件编码
原文:http://www.open-open.com/code/view/1420514359234 经常碰到用户上传的部分数据文本文件乱码问题,又不能限制用户的上传的文件编码格式(这样对客户的要求 ...
- IntelliJ IDEA 基本配置入门
前言:今天下载安装IntelliJ IDEA.随手创建了一个项目,运行Build提示错误. 与大多数用于开发JAVA的IDE类似,不做不论什么配置.编译是不会成功的.因此我尝试对IDEA的配置进行了一 ...
- Android拍照、摄像方向旋转的问题 代码具体解释
近期做了个拍照.摄像的应用.遇到了拍照.摄像的图像相对于现实.翻转了90度.原因:相机这个硬件的角度是横屏的角度,所以会出现都是横屏的. 1.照相.摄影预览图像的正确角度显 示: public sta ...
- 再谈用java实现Smtp发送邮件之Socket编程
很多其它内容欢迎訪问个人站点 http://icodeyou.com 前几天利用Socket实现了用java语言搭建webserver,全程下来应该会对Socket这个东西已经使用的很熟悉了.尽管 ...
- coco2d-js demo程序之滚动的小球
近期有一个游戏叫围住神经猫,报道说是使用html5技术来做的. html5的跨平台的优良特性非常不错.对于人手不足,技术不足,选用html5技术实现跨平台的梦想真是不错. 近期在看coco2d-js这 ...
- 谁是性能杀手?Kafka多Topic下启用SSL时延增大问题分析
问题背景 项目中将Kafka接口进行RESTful封装,在使用RESTful接口进行性能测试时,发现Topic数增多后,开启SSL与非SSL进行测试,发现开启SSL后性能下降得厉害.例如600个Top ...