torch.max
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
dimretained 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.
\]
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的更多相关文章
- torch.max与torch.argmax
形式: torch.max(input) → Tensor 返回输入tensor中所有元素的最大值: a = torch.randn(1, 3) >>0.4729 -0.2266 -0.2 ...
- (原)torch的训练过程
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6221622.html 参考网址: http://ju.outofmemory.cn/entry/284 ...
- PyTorch官方中文文档:torch.Tensor
torch.Tensor torch.Tensor是一种包含单一数据类型元素的多维矩阵. Torch定义了七种CPU tensor类型和八种GPU tensor类型: Data tyoe CPU te ...
- PyTorch官方中文文档:torch
torch 包 torch 包含了多维张量的数据结构以及基于其上的多种数学操作.另外,它也提供了多种工具,其中一些可以更有效地对张量和任意类型进行序列化. 它有CUDA 的对应实现,可以在NVIDIA ...
- torch分类问题
import torch from torch.autograd import Variable import torch.nn.functional as F import matplotlib.p ...
- pytorch max和clamp
torch.max() torch.max(a):数组a的最大值 torch.max(a, dim=1):多维数组沿维度1方向上的最大值,若a为二维数组,则为每行的最大值(此时是对每行的每列值比较取最 ...
- torch文档学习笔记
下面为官方文档学习笔记 http://pytorch.org/docs/0.3.0/index.html 1.torch.Tensor from __future__ import print_ ...
- torch基础学习
目录 Pytorch Leture 05: Linear Rregression in the Pytorch Way Logistic Regression 逻辑回归 - 二分类 Lecture07 ...
- pytorch中的view函数和max函数
一.view函数 代码: a=torch.randn(,,,) b = a.view(,-) print(b.size()) 输出: torch.Size([, ]) 解释: 其中参数-1表示剩下的值 ...
随机推荐
- elasticsearch 入门篇
前言: 要论入门最好的文档,非elasticsearch权威指南和官方的开发文档莫属,我只是基于这两份文档,记录一些关键知识点和自己的理解. 我们为什么要用elasticsearch,或者说来解决什么 ...
- python之滑动认证(图片)
from PIL import Image, ImageEnhance from io import BytesIO def cutImg(imgsrc): """ 根据 ...
- Codeforces F. Maxim and Array(构造贪心)
题目描述: Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- MySQL中建立Oracle中SCOTT数据示例
1.创建 scott 数据库 CREATE DATABASE scott; 2.创建 scott 数据库中的 dept 表 CREATE TABLE dept( deptno INT UNSIGNED ...
- sed练习2
[root@node2 ~]# cp /etc/passwd /server/scprits/ [root@node2 ~]# cd /server/scprits/ [root@node2 scpr ...
- 用python提取xml里面的链接源码
因群里朋友需要提取xml地图里面的链接,就写了这个程序. 代码: #coding=utf-8 import urllib import urllib.request import re url='ht ...
- VC 静态库与动态库(二)静态库创建与使用
1.新建项目,创建项目和解决方案 StaticLibrary 这是静态库项目 G:\C++Learn\Library Library文件夹用于存放库相关文件,包含静态库与后面的动态库工程和解决方案 ...
- LeetCode 112. Path Sum路径总和 (C++)
题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...
- Java中的 Invalid character constant(无效的字符常数)
将双引号误写成单引号,会出现这个错误. 1 package dftpkg; 2 3 public class Test { 4 5 public static void main(String[] a ...
- C++ string 字符串函数详解
运算符重载 + 和 +=:连接字符串 =:字符串赋值 >.>=.< 和 <=:字符串比较(例如a < b, aa < ab) ==.!=:比较字符串 << ...