日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

torch.roll() 详解

發(fā)布時(shí)間:2025/3/19 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 torch.roll() 详解 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

torch.roll(input,?shifts,?dims=None)

  • input?(Tensor) – the input tensor.

  • shifts?(int?or?tuple of python:ints) – The number of places by which the elements of the tensor are shifted. If shifts is a tuple, dims must be a tuple of the same size, and each dimension will be rolled by the corresponding value

  • dims?(int?or?tuple of python:ints) – Axis along which to roll

?

  • input?(Tensor) –輸入tensor

  • shifts?(int?or?tuple of python:ints) – 變換的幅度,為整數(shù)或者元組。若為元組,其shape與dims保持一樣

  • dims?(int?or?tuple of python:ints) – 維度。在dims維上進(jìn)行大小為shift的變換。0 為縱向,1為橫向

?

代碼示例:?

?

import torchx = torch.tensor([1, 2, 3, 4, 5, 6, 7, 8, 9]).view(3, 3) print(x, '\n') #tensor([[1, 2, 3], # [4, 5, 6], # [7, 8, 9]])print(1) print(torch.roll(x, (-1 , -1), (0 , 0)), '\n') #tensor([[7, 8, 9], # [1, 2, 3], # [4, 5, 6]])print(2) print(torch.roll(x, (-1 , 0), (0 , 1)), '\n') #tensor([[4, 5, 6], # [7, 8, 9], # [1, 2, 3]])print(3) print(torch.roll(x, (-1 , 1), (1 , 0)), '\n') #tensor([[8, 9, 7], # [2, 3, 1], # [5, 6, 4]])print(4) print(torch.roll(x, (0 , -1), (1 , 1)), '\n') #tensor([[2, 3, 1], # [5, 6, 4], # [8, 9, 7]])print(5) print(torch.roll(x, (0 , 0), (1 , 1)), '\n') #tensor([[1, 2, 3], # [4, 5, 6], # [7, 8, 9]])print(6) print(torch.roll(x, (0 , 1), (1 , 1)), '\n') #tensor([[3, 1, 2], # [6, 4, 5], # [9, 7, 8]])print(7) print(torch.roll(x, (1 , -1), (1 , 0)), '\n') #tensor([[6, 4, 5], # [9, 7, 8], # [3, 1, 2]])print(8) print(torch.roll(x, (1 , 0), (0 , 1)), '\n') #tensor([[7, 8, 9], # [1, 2, 3], # [4, 5, 6]])print(9) print(torch.roll(x, (1 , 1), (0 , 0)), '\n') #tensor([[4, 5, 6], # [7, 8, 9], # [1, 2, 3]])x = torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]).view(4, 2) print(x, '\n') #tensor([[1, 2], # [3, 4], # [5, 6], # [7, 8]])print(torch.roll(x, -3, 1), '\n') #tensor([[2, 1], # [4, 3], # [6, 5], # [8, 7]])print(torch.roll(x, -2, 1), '\n') #tensor([[1, 2], # [3, 4], # [5, 6], # [7, 8]])print(torch.roll(x, -1, 1), '\n') #tensor([[2, 1], # [4, 3], # [6, 5], # [8, 7]])print(torch.roll(x, 0, 1), '\n') #tensor([[1, 2], # [3, 4], # [5, 6], # [7, 8]])print(torch.roll(x, 1, 1), '\n') #tensor([[2, 1], # [4, 3], # [6, 5], # [8, 7]])print(torch.roll(x, 2, 1), '\n') #tensor([[1, 2], # [3, 4], # [5, 6], # [7, 8]])print(torch.roll(x, 3, 1), '\n') #tensor([[2, 1], # [4, 3], # [6, 5], # [8, 7]])print(torch.roll(x, -3, 0), '\n') #tensor([[7, 8], # [1, 2], # [3, 4], # [5, 6]])print(torch.roll(x, -2, 0), '\n') #tensor([[5, 6], # [7, 8], # [1, 2], # [3, 4]])print(torch.roll(x, -1, 0), '\n') #tensor([[3, 4], # [5, 6], # [7, 8], # [1, 2]])print(torch.roll(x, 0, 0), '\n') #tensor([[1, 2], # [3, 4], # [5, 6], # [7, 8]])print(torch.roll(x, 1, 0), '\n') #tensor([[7, 8], # [1, 2], # [3, 4], # [5, 6]])print(torch.roll(x, 2, 0), '\n') #tensor([[5, 6], # [7, 8], # [1, 2], # [3, 4]])print(torch.roll(x, 3, 0), '\n') #tensor([[3, 4], # [5, 6], # [7, 8], # [1, 2]])print(torch.roll(x, -3), '\n') #tensor([[4, 5], # [6, 7], # [8, 1], # [2, 3]])print(torch.roll(x, -2), '\n') #tensor([[3, 4], # [5, 6], # [7, 8], # [1, 2]])print(torch.roll(x, -1), '\n') #tensor([[2, 3], # [4, 5], # [6, 7], # [8, 1]])print(torch.roll(x, 0), '\n') #tensor([[1, 2], # [3, 4], # [5, 6], # [7, 8]])print(torch.roll(x, 1), '\n') #tensor([[8, 1], # [2, 3], # [4, 5], # [6, 7]])print(torch.roll(x, 2), '\n') #tensor([[7, 8], # [1, 2], # [3, 4], # [5, 6]])print(torch.roll(x, 3), '\n') #tensor([[6, 7], # [8, 1], # [2, 3], # [4, 5]])

?

?

參考:https://pytorch.org/docs/master/generated/torch.roll.html?

?

總結(jié)

以上是生活随笔為你收集整理的torch.roll() 详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。