torch.max()

>>> help(torch.max)
Help on built-in function max:
max(...)
    .. function:: max(input) -> Tensor
    
    Returns the maximum value of all elements in the :attr:`input` tensor.
    
    Args:
        {input}
    
    Example::
    
        >>> a = torch.randn(1, 3)
        >>> a
        tensor([[ 0.6763,  0.7445, -2.2369]])
        >>> torch.max(a)
        tensor(0.7445)
    
    .. function:: max(input, dim, keepdim=False, out=None) -> (Tensor, LongTensor)
    
    Returns a namedtuple ``(values, indices)`` where ``values`` is the maximum
    value of each row of the :attr:`input` tensor in the given dimension
    :attr:`dim`. And ``indices`` is the index location of each maximum value found
    (argmax).
    
    If :attr:`keepdim` is ``True``, the output tensors are of the same size
    as :attr:`input` except in the dimension :attr:`dim` where they are of size 1.
    Otherwise, :attr:`dim` is squeezed (see :func:`torch.squeeze`), resulting
    in the output tensors having 1 fewer dimension than :attr:`input`.
    
    Args:
        {input}
        {dim}
        {keepdim} Default: ``False``.
        out (tuple, optional): the result tuple of two output tensors (max, max_indices)
    
    Example::
    
        >>> 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]))
    
    .. function:: max(input, other, out=None) -> Tensor
    
    Each element of the tensor :attr:`input` is compared with the corresponding
    element of the tensor :attr:`other` and an element-wise maximum is taken.
    
    The shapes of :attr:`input` and :attr:`other` don't need to match,
    but they must be :ref:`broadcastable <broadcasting-semantics>`.
    
    .. math::
        \text{out}_i = \max(\text{tensor}_i, \text{other}_i)
    
    .. note:: When the shapes do not match, the shape of the returned output tensor
              follows the :ref:`broadcasting rules <broadcasting-semantics>`.
    
    Args:
        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])
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值