PyTorch torch.amax 函数
torch.amax 是 PyTorch 中用于返回张量沿指定维度的最大值的函数。
函数定义
torch.amax(input, dim, keepdim=False)
使用示例
实例
import torch
x = torch.tensor([[1, 3, 2], [4, 1, 3]])
# 返回所有元素的最大值
print("全局最大:", torch.amax(x))
# 沿 dim=0 最大值
print("dim=0 最大:", torch.amax(x, dim=0))
# 沿 dim=1 最大值
print("dim=1 最大:", torch.amax(x, dim=1))
x = torch.tensor([[1, 3, 2], [4, 1, 3]])
# 返回所有元素的最大值
print("全局最大:", torch.amax(x))
# 沿 dim=0 最大值
print("dim=0 最大:", torch.amax(x, dim=0))
# 沿 dim=1 最大值
print("dim=1 最大:", torch.amax(x, dim=1))
输出结果为:
全局最大: tensor(4) dim=0 最大: tensor([4, 3, 3]) dim=1 最大: tensor([3, 4])

Pytorch torch 参考手册