快捷鍵

torch.min

torch.min(input) Tensor

傳回 input tensor 中所有元素的最小值。

警告

min(dim=0) 不同,此函數產生確定性的(子)梯度。

參數

input (Tensor) – 輸入 tensor。

範例

>>> 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)

傳回一個 namedtuple (values, indices),其中 values 是給定維度 diminput tensor 每列的最小值。而 indices 是找到的每個最小值的索引位置 (argmin)。

如果 keepdimTrue,則輸出 tensors 的大小與 input 相同,除了在維度 dim 上它們的大小為 1。 否則,dim 會被擠壓(參見 torch.squeeze()),導致輸出 tensors 比 input 少一個維度。

注意

如果縮減的行中存在多個最小值,則返回第一個最小值的索引。

參數
  • input (Tensor) – 輸入 tensor。

  • dim (int) – 要縮減的維度。

  • keepdim (bool) – 輸出 tensor 是否保留 dim

關鍵字參數

out (tuple, optional) – 兩個輸出 tensors 的 tuple (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()

文件

取得 PyTorch 的完整開發人員文件

檢視文件

教學

取得初學者和進階開發人員的深入教學

檢視教學

資源

尋找開發資源並獲得問題解答

檢視資源