torch.min#
- torch.min(input, *, out=None) Tensor #
返回
input
张量中所有元素的最小值。示例
>>> 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)
,其中values
是input
张量在给定维度dim
中的每行的最小值。而indices
是找到的每个最小值的索引位置 (argmin)。如果
keepdim
为True
,则输出张量的尺寸与input
相同,只是在dim
维度上尺寸为 1。否则,dim
会被压缩 (参见torch.squeeze()
),导致输出张量的维度比input
少一个。注意
如果在一个归约行中存在多个最小值,则返回第一个最小值的索引。
- 参数
- 关键字参数
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()
。