网站建设中山优化,宿迁做网站哪家好,景观设计专业,企业宣传片拍摄制作分类目录#xff1a;《深入浅出Pytorch函数》总目录 相关文章#xff1a; 深入浅出Pytorch函数——torch.max 深入浅出Pytorch函数——torch.maximum torch.max有三种输入形式#xff0c;根据其输入形式及参数的不同有下列三种返回形式#xff1a;
torch.max(input)《深入浅出Pytorch函数》总目录 相关文章 · 深入浅出Pytorch函数——torch.max · 深入浅出Pytorch函数——torch.maximum torch.max有三种输入形式根据其输入形式及参数的不同有下列三种返回形式
torch.max(input)返回输入张量所有元素的最大值。torch.max(input, dim, keepdimFalse, *, outNone)返回输入张量给定维度上每行的最大值并同时返回每个最大值的位置索引。如果keepdim为True则输出张量的大小与输入张量的大小相同但尺寸为1的维度dim除外。否则dim会被挤压请参见torch.squeeze()即输出张量比输入少1个维度。torch.max(input, other, *, outNone)参考torch.maximum
语法
torch.max(input) - Tensor
torch.max(input, dim, keepdimFalse, *, outNone) - (values, indices)
torch.max(input, other, *, outNone) - Tensor参数
input[Tensor] 输入张量dim[int] 待求最大值维度的索引即返回值中被收缩维度的索引keepdim[bool] 是否保持输出张量与输入张量的形状一致默认为False
实例 a torch.randn(1, 3)a
tensor([[ 0.6763, 0.7445, -2.2369]])torch.max(a)
tensor(0.7445) a torch.randn(4, 5)a
tensor([[ 1.1299, -1.2838, -1.0533, -1.8278, 0.1653],[ 0.6461, 0.4583, 1.5229, -1.0642, -1.8352],[-0.9679, 1.1227, -0.2506, -0.4781, -0.2027],[ 0.2576, 0.7588, -0.1484, -0.0256, 0.7012]]) torch.max(a, 0)
torch.return_types.max(
valuestensor([ 1.1299, 1.1227, 1.5229, -0.0256, 0.7012]),
indicestensor([0, 2, 1, 3, 3])) torch.max(a, 1)
torch.return_types.max(
valuestensor([1.1299, 1.5229, 1.1227, 0.7588]),
indicestensor([0, 2, 1, 1]))