• 转onnx的时候maximum不支持,换成max,效果是一样的

获得 Tensor 元素中的最大值、最小值

1、torch.max()

torch.max(input, dim, keepdim=False)
返回命名元组(最大值,最大值索引),最大值是给定维度中的最大值,索引为在对应维度中的索引
当有多个最大值时,返回第一个最大值的索引
当没有指定维度 dim 时,则返回所有元素中的最大值(single value)
input:输入张量
dim:指定的维度
keepdim:默认 False,输出是否保留原始维度
在这里插入图片描述
torch 中还给出了直接获取最大值索引的方法 torch.argmax()

其用法和 torch.max() 一致,且结果即为 torch.max() 返回的第二个元组(索引的元组)

2、torch.min()

torch.min(input, dim, keepdim=False)

返回命名元组(最小值,最小值索引),最小值是给定维度中的最小值,索引为在对应维度中的索引

当有多个最小值时,返回第一个最小值的索引

当没有指定维度 dim 时,则返回所有元素中的最小值(single value)

input:输入张量

dim:指定的维度

在这里插入图片描述

torch 中还给出了直接获取最大值索引的方法 torch.argmin()

其用法和 torch.min() 一致,且结果即为 torch.min() 返回的第二个元组(索引的元组)

3、 torch.maximum()

计算输入张量成对比较的最大值

如果比较元素包含 NaN,则返回 NaN

torch.maximum(input,other)

input:输入张量

other:第二个输入张量,应与 input 同形状

在这里插入图片描述

4、torch.minimum()

计算输入张量成对比较的最小值

如果比较元素包含 NaN,则返回 NaN

torch.minimum(input,other)

input:输入张量

other:第二个输入张量,应与 input 同形状

在这里插入图片描述

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐