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. Python3的sorted

    排序算法 排序也是在程序中经常用到的算法.无论使用冒泡排序还是快速排序,排序的核心是比较两个元素的大小.如果是数字,我们可以直接比较,但如果是字符串或者两个dict呢?直接比较数学上的大小是没有意义的 ...

  2. ios--NavigationViewController跳转、返回传值

      使用NavigationViewController进行页面跳转时,应该使用pushViewController方法来跳转至下一页面,这样的话,下一页面同样在NavigationViewContr ...

  3. 【Java】理解ClassNotFoundException与NoClassDefFoundError的区别

    一.概念上的认识 1)Exception与Error的区别 1.Exception的出现不会导致程序结束,用户程序可以捕获该异常 2.Error的出现会导致程序结束,用户程序无法捕获Error错误 2 ...

  4. Python从零开始——字符串String

    一:Python字符串有哪些内容 二:Python字符串操作符 三:Python字符串格式化——占位符格式化 四:Python字符串格式化——format()函数 五:Python字符串常用操作函数

  5. 201777010217-金云馨《面向对象程序设计(java)》第十四周学习总结

      项目 内容   这个作业属于哪个课程   https://www.cnblogs.com/nwnu-daizh/   这个作业的要求在哪里 https://www.cnblogs.com/nwnu ...

  6. LG2598/BZOJ1412 「ZJOI2009」狼和羊的故事 最小割

    问题描述 LG2598 BZOJ1412 题解 看到要把狼和羊两个物种分开 自然想到最小割. 发现\((x,y)\)可以向上下左右走以获得贡献,所以建边:\((x,y),(x-1,y)\),\((x, ...

  7. 「总结」插头$dp$

    集中做完了插头$dp$ 写一下题解. 一开始学的时候还是挺蒙的. 不过后来站在轮廓线$dp$的角度上来看就简单多了. 其实就是一种联通性$dp$,只不过情况比较多而已了. 本来转移方式有两种.逐行和逐 ...

  8. DNS用的是TCP协议还是UDP协议

    DNS占用53号端口,同时使用TCP和UDP协议.那么DNS在什么情况下使用这两种协议? DNS在区域传输的时候使用TCP协议,其他时候使用UDP协议. DNS区域传输的时候使用TCP协议: 1.辅域 ...

  9. [ Python入门教程 ] Python基础语法

    Python的语法非常简练,因此用Python编写的程序可读性强.容易理解.本章将介绍Python的基本语法和概念. Python文件类型 1.源代码.Python的源代码的扩展名以py结尾,可直接运 ...

  10. CF1194F Crossword Expert(数论,组合数学)

    不难的一题.不知道为什么能 $2500$…… 不过场上推错了一直不会优化…… 首先考虑 $f_i$ 表示恰好做完前 $i$ 道题的概率. 这样很难算.修改一下,$f_i$ 表示做完至少 $i$ 道题的 ...