torch.max¶
- torch.max(input) 张量¶
返回
input张量中所有元素的最大值。警告
与
max(dim=0)不同,此函数生成确定性(子)梯度- Parameters
输入 (张量) – 输入张量。
示例:
>>> 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)
返回一个命名元组
(values, indices),其中values是给定维度dim中每个输入张量行的最大值。而indices是找到的每个最大值的索引位置(argmax)。如果
keepdim是True,输出张量的大小与input相同,除了在维度dim上它们的大小为1。 否则,dim被压缩(参见torch.squeeze()),导致输出张量的维度比input少1。注意
如果在缩减行中存在多个最大值,则返回第一个最大值的索引。
- Parameters
- Keyword Arguments
输出 (元组, 可选) – 包含两个输出张量的结果元组 (max, max_indices)
示例:
>>> 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]))
- torch.max(input, other, *, out=None) 张量
参见
torch.maximum()。