YouTip LogoYouTip

Pytorch Torch Kthvalue

# PyTorch torch.kthvalue Function
Image 3: PyTorch torch Reference Manual 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)
Image 4: PyTorch torch Reference Manual 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
← Pytorch Torch LdexpPytorch Torch Kaiser_Window β†’