首页 > 其他分享 >torch.max

torch.max

时间:2022-09-20 21:14:18浏览次数:55  
标签:dim tensor max torch indices input

第一个版本

torch.max(input) → Tensor

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

>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.6763,  0.7445, -2.2369]])
>>> torch.max(a)
tensor(0.7445)

第二个版本

torch.max(input, dim, keepdim=False, *, out=None)
  • 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).
  • If keepdim is True, the output tensors are of the same size as input except in the dimension dim where they are of size 1. Otherwise, dim is squeezed (see torch.squeeze()), resulting in the output tensors having 1 fewer dimension than input.

If there are multiple maximal values in a reduced row then the indices of the first maximal value are returned.  

Parameters

  • input (Tensor) – the input tensor.

  • dim (int) – the dimension to reduce.

  • keepdim (bool) – whether the output tensor has dim retained or not. Default: False.

>>> a = torch.randn(4, 4)
>>> a
tensor([[-1.2360, -0.2942, -0.1222,  0.8475],
        [ 1.1949, -1.1127, -2.2379, -0.6702],
        [ 1.5717, -0.9207,  0.1297, -1.8768],
        [-0.6172,  1.0036, -0.6060, -0.2432]])
>>> torch.max(a, 1)
torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))

  

   

标签:dim,tensor,max,torch,indices,input
From: https://www.cnblogs.com/zjuhaohaoxuexi/p/16712536.html

相关文章

  • torch.Tensor.index_fill_
    torch.Tensor.index_fill_(dim,index,value)→TensorFillstheelementsofthe self tensorwithvalue value byselectingtheindicesintheordergiven......
  • PyTorch 中的 CIFAR10 图像分类
    PyTorch中的CIFAR10图像分类如何为CIFAR10构建高精度CNNPhotoby伊戈尔·莱皮林on不飞溅在本文中,我们将深入探讨CIFAR10图像分类问题。为了解决这个问题,......
  • linux系统 net.core.somaxconn参数
    1、如何查看该参数值1)查看所有内核参数及值sysctl-a #查看所有内核参数及值2)查看net.core.somaxconn参数[root@localhost]#sysctl-a|grepnet.co......
  • pytorch 随机数种子
    https://zhuanlan.zhihu.com/p/391875795https://zhuanlan.zhihu.com/p/419063125可复现性在硬件设备(CPU、GPU)不同时,完全的可复现性无法保证,即使随机种子相同。但是,在同......
  • torch.nn.KLDivLoss
    CLASStorch.nn.KLDivLoss(size_average=None,reduce=None,reduction='mean',log_target=False)TheKullback-Leiblerdivergenceloss.Fortensorsofthesames......
  • pytorch学习
    #https://blog.csdn.net/qq_27825451/article/details/90705328#https://blog.csdn.net/qq_27825451/article/details/90550890"""1.torch.nn.Module的基本属性tor......
  • 查看当前pytorch的cuda版本
    https://stackoverflow.com/questions/64089854/pytorch-detection-of-cudaInthecondaenv(myenv)wherepytorchisinstalleddothefollowing:condaactivatemye......
  • Smallest Subarrays With Maximum Bitwise OR
    SmallestSubarraysWithMaximumBitwiseORYouaregivena0-indexedarray nums oflength$n$,consistingofnon-negativeintegers.Foreachindex$i$from$......
  • Max-Min Sums(组合计数,算贡献)
    题意对于一个有限集合\(X\),令\(f(X)=\maxX-\minX\)给定\(N\)个整数\(A_1,A_2,\dots,A_N\)我们要从中选择\(K\)个元素构成一个新的集合\(S\)。如果我们根据下标......
  • 关于 pytorch 版本问题及快捷键
    1.查看cuda版本nvcc--version该命令也可以简写成nvcc-V虚拟环境中的cuda和系统安装的cuda是互不影响的,所以,在虚拟环境中可以随意更改cuda版本。在更新cuda......