分類目錄:《深入淺出Pytorch函數(shù)》總目錄
相關(guān)文章:
· 深入淺出Pytorch函數(shù)——torch.max
· 深入淺出Pytorch函數(shù)——torch.maximum文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-607201.html
torch.max
有三種輸入形式,根據(jù)其輸入形式及參數(shù)的不同有下列三種返回形式:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-607201.html
-
torch.max(input)
:返回輸入張量所有元素的最大值。 -
torch.max(input, dim, keepdim=False, *, out=None)
:返回輸入張量給定維度上每行的最大值,并同時(shí)返回每個(gè)最大值的位置索引。如果keepdim
為True
,則輸出張量的大小與輸入張量的大小相同,但尺寸為1的維度dim
除外。否則,dim
會(huì)被擠壓(請(qǐng)參見(jiàn)torch.squeeze()
),即輸出張量比輸入少1個(gè)維度。 -
torch.max(input, other, *, out=None)
:參考torch.maximum
語(yǔ)法
torch.max(input) -> Tensor
torch.max(input, dim, keepdim=False, *, out=None) -> (values, indices)
torch.max(input, other, *, out=None) -> Tensor
參數(shù)
-
input
:[Tensor
] 輸入張量 -
dim
:[int
] 待求最大值維度的索引,即返回值中被收縮維度的索引 -
keepdim
:[bool
] 是否保持輸出張量與輸入張量的形狀一致,默認(rèn)為False
實(shí)例
>>> 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(
values=tensor([ 1.1299, 1.1227, 1.5229, -0.0256, 0.7012]),
indices=tensor([0, 2, 1, 3, 3]))
>>> torch.max(a, 1)
torch.return_types.max(
values=tensor([1.1299, 1.5229, 1.1227, 0.7588]),
indices=tensor([0, 2, 1, 1]))
到了這里,關(guān)于深入淺出Pytorch函數(shù)——torch.max的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!