本文簡要介紹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 張量並且有多個有效的k
th 值時,此函數可能會不確定地為其中任何一個返回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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。