torch.min()
is a PyTorch function that computes the minimum value of a given input tensor along a specified dimension.
The torch.min()
function takes two arguments:
-
input
: the input tensor to be reduced -
dim
: the dimension along which to find the minimum value
For example, if input
is a 2D tensor of shape (3, 4)
and we want to find the minimum value along the second dimension, we can call torch.min(input, dim=1)
.
This will return a tuple of two tensors:
-
The first tensor will contain the minimum value of each row, resulting in a 1D tensor of shape
(3,)
. -
The second tensor will contain the index of the minimum value of each row, resulting in a 1D tensor of shape
(3,)
.
If we set keepdim=True
, the output tensors will have the same number of dimensions as the input tensor, with the reduced dimension replaced by a singleton dimension. For example, if we call torch.min(input, dim=1, keepdim=True)
, the first output tensor will have shape (3, 1)
and the second output tensor will have shape (3, 1)
.
The torch.min()
function can also take multiple input tensors as arguments, in which case it will compute the element-wise minimum of the tensors along the specified dimension.