zoukankan      html  css  js  c++  java
  • 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 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().

  • 相关阅读:
    暑假学习日记2013/7/20
    java二维码之利用谷歌的zxing生成二维码,解析二维码
    数组去重
    MVC VS2012 Code First 数据库迁移教程
    WIN8 MTK驱动不能安装解决办法
    洛谷 P1943 LocalMaxima_NOI导刊2009提高(1)
    BZOJ 1572 USACO 2009 Open 工作安排
    BZOJ 1724 USACO 2006 Nov. 切割木板
    BZOJ 1666 USACO 2006 Oct. 奶牛的数字游戏
    BZOJ 4094 USACO 2013 Dec. Optimal Milking
  • 原文地址:https://www.cnblogs.com/xxxxxxxxx/p/11117727.html
Copyright © 2011-2022 走看看