torch.max¶
- torch.max(input) Tensor ¶
傳回
input
張量中所有元素的最大值。警告
此函式會產生確定性的(子)梯度,不像
max(dim=0)
- 參數
input (Tensor) – 輸入張量 (input tensor)。
範例
>>> a = torch.randn(1, 3) >>> a tensor([[ 0.6763, 0.7445, -2.2369]]) >>> torch.max(a) tensor(0.7445)
- torch.max(input, dim, keepdim=False, *, out=None)
傳回一個具名元組
(values, indices)
,其中values
是input
張量在給定維度dim
中每一列的最大值。indices
是找到的每個最大值的索引位置 (argmax)。如果
keepdim
為True
,則輸出張量的大小與input
相同,除了維度dim
,其大小為 1。 否則,dim
會被擠壓(squeeze)(請參閱torch.squeeze()
),導致輸出張量的維度比input
少 1。注意
如果在縮減後的列中存在多個最大值,則傳回第一個最大值的索引。
- 參數
- 關鍵字引數
out (tuple, optional) – 兩個輸出張量 (max, max_indices) 的結果元組
範例
>>> a = torch.randn(4, 4) >>> a tensor([[-1.2360, -0.2942, -0.1222, 0.8475], [ 1.1949, -1.1127, -2.2379, -0.6702], [ 1.5717, -0.9207, 0.1297, -1.8768], [-0.6172, 1.0036, -0.6060, -0.2432]]) >>> torch.max(a, 1) torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
- torch.max(input, other, *, out=None) Tensor
請參閱
torch.maximum()
。