本文簡要介紹python語言中 torch.roll
的用法。
用法:
torch.roll(input, shifts, dims=None) → Tensor
沿給定維度滾動張量。超出最後一個位置的元素在第一個位置重新引入。如果未指定尺寸,張量將在滾動前被展平,然後恢複到原始形狀。
例子:
>>> x = torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]).view(4, 2) >>> x tensor([[1, 2], [3, 4], [5, 6], [7, 8]]) >>> torch.roll(x, 1, 0) tensor([[7, 8], [1, 2], [3, 4], [5, 6]]) >>> torch.roll(x, -1, 0) tensor([[3, 4], [5, 6], [7, 8], [1, 2]]) >>> torch.roll(x, shifts=(2, 1), dims=(0, 1)) tensor([[6, 5], [8, 7], [2, 1], [4, 3]])
參數:
相關用法
- Python PyTorch round用法及代碼示例
- Python PyTorch rot90用法及代碼示例
- Python PyTorch renorm用法及代碼示例
- Python PyTorch rpc_sync用法及代碼示例
- Python PyTorch reshape用法及代碼示例
- Python PyTorch rand_split_train_val用法及代碼示例
- Python PyTorch randn用法及代碼示例
- Python PyTorch rad2deg用法及代碼示例
- Python PyTorch real用法及代碼示例
- Python PyTorch rsqrt用法及代碼示例
- Python PyTorch rfftn用法及代碼示例
- Python PyTorch rpc_async用法及代碼示例
- Python PyTorch repeat_interleave用法及代碼示例
- Python PyTorch random_split用法及代碼示例
- Python PyTorch remove用法及代碼示例
- Python PyTorch read_vec_flt_ark用法及代碼示例
- Python PyTorch rfft用法及代碼示例
- Python PyTorch register_kl用法及代碼示例
- Python PyTorch read_vec_int_ark用法及代碼示例
- Python PyTorch resolve_neg用法及代碼示例
- Python PyTorch remainder用法及代碼示例
- Python PyTorch register_module_forward_pre_hook用法及代碼示例
- Python PyTorch random_structured用法及代碼示例
- Python PyTorch remote用法及代碼示例
- Python PyTorch rand用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.roll。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。