torch.kthvalue¶
- torch.kthvalue(input, k, dim=None, keepdim=False, *, out=None)¶
- Returns a namedtuple - (values, indices)where- valuesis the- kth smallest element of each row of the- inputtensor in the given dimension- dim. And- indicesis the index location of each element found.- If - dimis not given, the last dimension of the input is chosen.- If - keepdimis- True, both the- valuesand- indicestensors are the same size as- input, except in the dimension- dimwhere they are of size 1. Otherwise,- dimis squeezed (see- torch.squeeze()), resulting in both the- valuesand- indicestensors having 1 fewer dimension than the- inputtensor.- Note - When - inputis a CUDA tensor and there are multiple valid- kth values, this function may nondeterministically return- indicesfor any of them.- Parameters
- Keyword Arguments
- out (tuple, optional) – the output tuple of (Tensor, LongTensor) can be optionally given to be used as output buffers 
 - Example: - >>> x = torch.arange(1., 6.) >>> x tensor([ 1., 2., 3., 4., 5.]) >>> torch.kthvalue(x, 4) torch.return_types.kthvalue(values=tensor(4.), indices=tensor(3)) >>> x=torch.arange(1.,7.).resize_(2,3) >>> x tensor([[ 1., 2., 3.], [ 4., 5., 6.]]) >>> torch.kthvalue(x, 2, 0, True) torch.return_types.kthvalue(values=tensor([[4., 5., 6.]]), indices=tensor([[1, 1, 1]]))