torch.min、torch.max、torch.argmax

t o r c h . m i n 、 t o r c h . m a x 、 t o r c h . a r g m a x torch.min、torch.max、torch.argmax torch.mintorch.maxtorch.argmax

torch.max()和torch.min()是比较tensor大小的函数

x = torch.rand(1,3)
print(x)
print(torch.min(x))
 
y = torch.rand(2,3)
print(y)
print(torch.min(y))

在这里插入图片描述

指定比较维度:torch.max(input,dim)

y = torch.rand(5,3)
print("***********")
print(y)
print("***********")
print(torch.max(y,0))

在这里插入图片描述

y = torch.rand(5,6)
print("***********")
print(y)
print("***********")
print(torch.max(y,1))

在这里插入图片描述

两个tensor相比较:不一定是相同大小结构

若不是相同大小结构,必须满足可广播

x = torch.rand(2,3)
y = torch.rand(2,3)
print("***********")
print(x)
print("***********")
print(y)
print("*****比较结果******")
print(torch.max(x,y))

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_41375318/article/details/114629760