## Example Usage ## Example import torch # Create tensor x = torch.tensor([3,1,2,4]) # Returns the 2nd smallest value and index values, indices = torch.kthvalue(x,2) print(values) print(indices) Output result: tensor(2) tensor(2)
Pytorch Torch Kthvalue
# PyTorch torch.kthvalue Function
PyTorch torch Reference Manual
`torch.kthvalue` is a PyTorch function for returning the k-th smallest value. It returns the k-th smallest value and its index along the specified dimension of the input tensor.
### Function Definition
torch.kthvalue(input, k, dim=None, keepdim=False)
## Example Usage ## Example import torch # Create tensor x = torch.tensor([3,1,2,4]) # Returns the 2nd smallest value and index values, indices = torch.kthvalue(x,2) print(values) print(indices) Output result: tensor(2) tensor(2)
PyTorch torch Reference Manual
PyTorch Data Transforms
PyTorch torch.nn Reference Manual
iFlytek Spark Coding Plan includes free model call quotas for DeepSeek, GLM, Kimi, MiniMax, one-stop platform for experience and deployment. Configuration Guide Β₯3.9/month Subscribe Now
## Example Usage ## Example import torch # Create tensor x = torch.tensor([3,1,2,4]) # Returns the 2nd smallest value and index values, indices = torch.kthvalue(x,2) print(values) print(indices) Output result: tensor(2) tensor(2)
YouTip