本文简要介绍python语言中 torch.kthvalue 的用法。
用法:
torch.kthvalue(input, k, dim=None, keepdim=False, *, out=None)out(tuple,可选的) -(Tensor, LongTensor) 的输出元组可以选择用作输出缓冲区
返回一个命名元组
(values, indices)其中values是给定维度dim中input张量的每一行的第k个最小元素。而indices是找到的每个元素的索引位置。如果没有给出
dim,则选择input的最后一个维度。如果
keepdim是True,则values和indices张量的大小都与input相同,除了在维度dim中它们的大小为 1。否则,dim被压缩(见torch.squeeze()),导致values和indices张量比input张量少 1 个维度。注意
当
input是 CUDA 张量并且有多个有效的kth 值时,此函数可能会不确定地为其中任何一个返回indices。例子:
>>> 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]]))
参数:
关键字参数:
相关用法
- Python PyTorch kron用法及代码示例
- Python PyTorch kaiming_normal_用法及代码示例
- Python PyTorch keypointrcnn_resnet50_fpn用法及代码示例
- Python PyTorch kaiming_uniform_用法及代码示例
- Python PyTorch frexp用法及代码示例
- Python PyTorch jvp用法及代码示例
- Python PyTorch cholesky用法及代码示例
- Python PyTorch vdot用法及代码示例
- Python PyTorch ELU用法及代码示例
- Python PyTorch ScaledDotProduct.__init__用法及代码示例
- Python PyTorch gumbel_softmax用法及代码示例
- Python PyTorch get_tokenizer用法及代码示例
- Python PyTorch saved_tensors_hooks用法及代码示例
- Python PyTorch positive用法及代码示例
- Python PyTorch renorm用法及代码示例
- Python PyTorch AvgPool2d用法及代码示例
- Python PyTorch MaxUnpool3d用法及代码示例
- Python PyTorch Bernoulli用法及代码示例
- Python PyTorch Tensor.unflatten用法及代码示例
- Python PyTorch Sigmoid用法及代码示例
- Python PyTorch Tensor.register_hook用法及代码示例
- Python PyTorch ShardedEmbeddingBagCollection.named_parameters用法及代码示例
- Python PyTorch sqrt用法及代码示例
- Python PyTorch PackageImporter.id用法及代码示例
- Python PyTorch column_stack用法及代码示例
注:本文由纯净天空筛选整理自pytorch.org大神的英文原创作品 torch.kthvalue。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
