• 文档 >
  • torch >
  • torch.max
快捷键

torch.max

torch.max(input) Tensor

返回张量 input 中所有元素的最大值。

参数:

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)

返回一个命名元组 (values, indices) ,其中 valuesinput 张量在给定维度 dim 上的每行的最大值。 indices 是找到的每个最大值的索引位置(argmax)。

如果 keepdimTrue ,则输出张量的大小与 input 相同,除了在维度 dim 上大小为 1。否则, dim 被挤压(见 torch.squeeze() ),导致输出张量比 input 少一个维度。

注意

如果在减少的行中有多个最大值,则返回第一个最大值的索引。

参数:
  • input (Tensor) – 输入张量。

  • dim(int 或 int 元组,可选)- 要降低的维度或维度。如果为 None ,则降低所有维度。

  • keepdim(布尔值,可选)- 输出张量是否保留 dim 。默认: False

关键字参数:

out(元组,可选)- 两个输出张量(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]))
>>> a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
>>> a.max(dim=1, keepdim=True)
torch.return_types.max(
values=tensor([[2.], [4.]]),
indices=tensor([[1], [1]]))
>>> a.max(dim=1, keepdim=False)
torch.return_types.max(
values=tensor([2., 4.]),
indices=tensor([1, 1]))
torch.max(input, other, *, out=None) Tensor

torch.maximum()


© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,并使用 Read the Docs 提供的主题。

文档

PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源