torch.max()


torch.max(input) -> Tensor

Explation:

​ Returns the maximum value of all elements in the input tensor

Example:

>>> a = torch.randn(1, 3)
>>> a
tensor([[-0.7461, -0.7730, 0.6381]])
>>> torch.max(a)
tensor(0.6381)

torch.max(input, dim, keepdim=False, out=None) ->(Tensor, LongTensor)

Explation:

​ Returns a namedtuple (values, indices) where values is the maximum value of each row of the input tensor in the given dimension dim. And indices is the index location of each maximum value found (argmax).

Parameters:

  • input(Tensor) - the input tensor
  • dim(int) - the dimension to reduce
  • keepdim(bool, optional) - whether the output tensors have dim retained or not. Default: False.
  • out(tuple, optional) - the result tuple of two output tensors (max, max_indices)

Example:

>>> a = torch.randn(4, 4)
tensor([[-0.7037, -0.9814, -0.2549, 0.7349],
[-0.0937, 0.9692, -0.2475, -0.3693],
[ 0.5427, 0.9605, 0.2246, 0.3269],
[-0.9964, 0.6920, 0.7989, -0.2616]])
>>> torch.max(a)
torch.return_types.max(values=tensor([0.7349, 0.9692, 0.9605, 0.7989]),
indices=tensor([3, 1, 1, 2]))

torch.max(input, other, out=None) ->Tensor

Explation:

​ Each element of the tensor input is compared with the corresponding element of the tensor other and an element-wise maximum is taken. The shapes of input and other don’t need to match, but they must be broadcastable.

\[out_i = \max(tensor_i, other_i)
\]

Parameters:

  • input(Tensor) - the input tensor
  • other(Tensor) - the second input tensor
  • out(Tensor, optional) - the output tensor

Example:

>>> a = torch.randn(4)
>>> a
tensor([ 0.2942, -0.7416, 0.2653, -0.1584])
>>> b = torch.randn(4)
>>> b
tensor([ 0.8722, -1.7421, -0.4141, -0.5055])
>>> torch.max(a, b)
tensor([ 0.8722, -0.7416, 0.2653, -0.1584])

同理,这些方法可推广至torch.min().

torch.max的更多相关文章

  1. torch.max与torch.argmax

    形式: torch.max(input) → Tensor 返回输入tensor中所有元素的最大值: a = torch.randn(1, 3) >>0.4729 -0.2266 -0.2 ...

  2. (原)torch的训练过程

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6221622.html 参考网址: http://ju.outofmemory.cn/entry/284 ...

  3. PyTorch官方中文文档:torch.Tensor

    torch.Tensor torch.Tensor是一种包含单一数据类型元素的多维矩阵. Torch定义了七种CPU tensor类型和八种GPU tensor类型: Data tyoe CPU te ...

  4. PyTorch官方中文文档:torch

    torch 包 torch 包含了多维张量的数据结构以及基于其上的多种数学操作.另外,它也提供了多种工具,其中一些可以更有效地对张量和任意类型进行序列化. 它有CUDA 的对应实现,可以在NVIDIA ...

  5. torch分类问题

    import torch from torch.autograd import Variable import torch.nn.functional as F import matplotlib.p ...

  6. pytorch max和clamp

    torch.max() torch.max(a):数组a的最大值 torch.max(a, dim=1):多维数组沿维度1方向上的最大值,若a为二维数组,则为每行的最大值(此时是对每行的每列值比较取最 ...

  7. torch文档学习笔记

    下面为官方文档学习笔记    http://pytorch.org/docs/0.3.0/index.html 1.torch.Tensor from __future__ import print_ ...

  8. torch基础学习

    目录 Pytorch Leture 05: Linear Rregression in the Pytorch Way Logistic Regression 逻辑回归 - 二分类 Lecture07 ...

  9. pytorch中的view函数和max函数

    一.view函数 代码: a=torch.randn(,,,) b = a.view(,-) print(b.size()) 输出: torch.Size([, ]) 解释: 其中参数-1表示剩下的值 ...

随机推荐

  1. Java 打印HelloKitty

    Java第一课 如何在控制台打印出"Hello Kitty" 如图所示,在IDE中使用 System.out.println(); 语句来实现打印 最后附上AIDE下载链接: Ja ...

  2. 【原创】Talend 配置SSL支持gitlab

    背景 talend的源代码控制用的是gitlab,以前都是http方式的,但是最近突然改了https,所以talend登录失败,必须要SSL方式才能获取到分支等数据,才能提交代码. 证书导入 1.ta ...

  3. 【原创】Airflow 简介&如何部署一个健壮的 apache-airflow 调度系统

    声明 本文摘录了很多前辈的文章,原文如下: https://www.jianshu.com/p/2ecef979c606 Airflow 简介 Airflow是一个可编程,调度和监控的工作流平台,基于 ...

  4. 强大的 strace 工具

    什么是 strace strace是Linux环境下的一款程序调试工具,用来监察一个应用程序所使用的系统调用. Strace是一个简单的跟踪系统调用执行的工具.在其最简单的形式中,它可以从开始到结束跟 ...

  5. hydra使用,实例介绍

    hydra 是一个网络帐号破解工具,支持多种协议.其作者是van Hauser,David Maciejak与其共同维护.hydra在所有支持GCC的平台能很好的编译,包括Linux,所有版本的BSD ...

  6. 快速、优雅的前端IDE之H-builder-X

    为什么介绍的是HBuidler-X而不是Hbuilder   HX是全新的一个软件,它抛弃了eclipse架构,使用C++为基础架构.HX目前还不能完全替代HBuilder.但在markdown记事的 ...

  7. vue报错 Uncaught (in promise) NavigationDuplicated {_name:""NavigationDuplicated"... 的解决方法

    在进行跳转的时候报错 app.js:87499 Uncaught (in promise) NavigationDuplicated?{_name: "NavigationDuplicate ...

  8. c语言的布尔量

    #include <stdio.h> #include <stdbool.h> int main() { bool b = true; bool t = false; ; }

  9. P5008 [yLOI2018] 锦鲤抄(Tarjan+贪心)

    洛谷 题意: 给出一个有向图,每次可以删除存在入度的点及其出边,每次删除一个点可以获得其权值. 问最终能够获得的最大权值为多少. 思路: 考虑DAG:我们直接倒着拓扑序来选,即可将所有入度不为\(0\ ...

  10. 201871010136-赵艳强《面向对象程序设计(java)》第六,七周学习总结

            201871010136-赵艳强<面向对象程序设计(java)>第六七周学习总结 项目 内容 这个作业属于哪个课程 <任课教师博客主页链接> https://w ...