評價此頁

torch.min#

torch.min(input, *, out=None) Tensor#

返回 input 張量中所有元素的最小值。

注意

max/minamax/amin 之間的區別在於
  • amax/amin 支援在多個維度上進行歸約,

  • amax/amin 不返回索引。

當有多個輸入元素具有相同的最小或最大值時,amax/amin 會在這些值之間均勻分配梯度。

對於 max/min
  • 如果對所有維度進行歸約(未指定 dim),則梯度會在相等的 max/min 值之間均勻分配。

  • 如果在一指定的軸上進行歸約,則只傳播到索引的元素。

引數

input (Tensor) – 輸入張量。

關鍵字引數

out (Tensor, optional) – 輸出張量。

示例

>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.6750,  1.0857,  1.7197]])
>>> torch.min(a)
tensor(0.6750)
torch.min(input, dim, keepdim=False, *, out=None)

返回一個命名元組 (values, indices),其中 valuesinput 張量在給定維度 dim 上每行的最小值。 indices 是找到的每個最小值的索引位置 (argmin)。

如果 keepdimTrue,則輸出張量的大小與 input 相同,但 dim 維度的大小為 1。否則,dim 將被擠壓(參見 torch.squeeze()),導致輸出張量的維度比 input 少 1。

注意

如果在歸約的行中有多個最小值,則返回第一個最小值的索引。

引數
  • input (Tensor) – 輸入張量。

  • dim (int, optional) – 要歸約的維度。如果省略,則歸約所有維度。顯式的 None 不受支援。

  • keepdim (bool, optional) – 輸出張量是否保留 dim。預設為 False

關鍵字引數

out (tuple, optional) – 包含兩個輸出張量的元組(min, min_indices)

示例

>>> a = torch.randn(4, 4)
>>> a
tensor([[-0.6248,  1.1334, -1.1899, -0.2803],
        [-1.4644, -0.2635, -0.3651,  0.6134],
        [ 0.2457,  0.0384,  1.0128,  0.7015],
        [-0.1153,  2.9849,  2.1458,  0.5788]])
>>> torch.min(a, 1)
torch.return_types.min(values=tensor([-1.1899, -1.4644,  0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
torch.min(input, other, *, out=None) Tensor

參見 torch.minimum()