当前位置:网站首页>torch.roll()
torch.roll()
2022-08-05 02:33:00 【00000cj】
torch.roll(input, shifts, dims=None) -> Tensor
Definition
Scrolls the tensor input along the given dimension.Elements beyond the last position are reintroduced at the first position.If dims is None, the tensor will be flattened before rolling and then restored to its original shape.
Parameters
- input (Tensor) - input tensor
- shifts (int or tuple of python: ints) - The number of positions to shift the elements of the tensor.If shifts is a tuple, dims must be a tuple of the same size, with each dimension rolling the corresponding value
- dims (int or tuple of python: ints) - scroll along the dimension specified by dims
Example
import torchx = torch.tensor([1, 2, 3, 4, 5, 6, 7, 8]).view(4, 2)print(x)# tensor([[1, 2],# [3, 4],# [5, 6],# [7, 8]])x1 = torch.roll(x, 1)print(x1)# tensor([[8, 1],# [twenty three],# [4, 5],# [6, 7]])x2 = torch.roll(x, 1, 0)print(x2)# tensor([[7, 8],# [1, 2],# [3, 4],# [5, 6]])x3 = torch.roll(x, -1, 0)print(x3)# tensor([[3, 4],# [5, 6],# [7, 8],# [1, 2]])x4 = torch.roll(x, shifts=(2, 1), dims=(0, 1))print(x4)# tensor([[6, 5],# [8, 7],# [twenty one],# [4, 3]])Reference
边栏推荐
猜你喜欢
随机推荐
浅谈数据安全治理与隐私计算
undo问题
1527. 患某种疾病的患者
Matlab map with color representation module value size arrow
关于#sql shell#的问题,如何解决?
线上MySQL的自增id用尽怎么办?
leetcode 15
Snapback - same tree
nodeJs--封装路由
Error: Not a signal or slot declaration
[In-depth study of 4G/5G/6G topic-51]: URLLC-16-"3GPP URLLC related protocols, specifications, and technical principles in-depth interpretation"-11-High reliability technology-2-Link adaptive enhancem
【LeetCode刷题】-数之和专题(待补充更多题目)
使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号
继承关系下构造方法的访问特点
C语言日记 9 if的3种语句
后期学习计划
学习笔记-----左偏树
Intel XDC 2022 Wonderful Review: Build an Open Ecosystem and Unleash the Potential of "Infrastructure"
树表的查找
散列表的查找(哈希表)









