max和argmax的名字看起来很相似,但差别很大
max_num,index=Torch.max(Tensor,dim=? 返回指定维的最大数量及其索引,如下所示
b=torch.tensor ([ [ 3,2 ],[ 1,4 ],[ 5,6 ],[ 7,8 ] ] ) print(b ) b ) max_num,index=torch.max(b
输出:
tensor ([ [ 3,2 ],[ 1,4 ] ],[ [ 5,6 ],[ 7,8 ] ] ) * * * * * * * * * * * * * * * * * * * * * * * * *。
b=torch.tensor ([ [ 3,2 ],[ 1,4 ],[ 5,6 ],[ 7,8 ] ] ) print(b ) b ) print('*'*50 )索引=torch
输出:
输出: tensor ([ [ 3,2 ],[ 1,4 ] ],[ [ 5,6 ],[ 7,8 ] ] ) * * * * * * * * * * * * * * * * * * * * * * * *。
torch.min
b=torch.tensor ([ [ 3,2 ],[ 1,4 ],[ 5,6 ],[ 7,8 ] ] ) min_num,index=torch.min(b ) b,dim=1
输出:
tensor ([ [ 3,2 ],[ 1,4 ] ],[ [ 5,6 ],[ 7,8 ] ] ) * * * * * * * * * * * * * * * * * * * * * * * * *。
torch.argmin
b=torch.tensor ([ [ 3,2 ],[ 1,4 ],[ 5,6 ],[ 7,8 ] ] )索引=torch.arg min (b ) b,dim=1)打印(b
输出:
tensor ([ [ 3,2 ],[ 1,4 ] ],[ [ 5,6 ],[ 7,8 ] ] ) * * * * * * * * * * * * * * * * * * * * * * * * *。