当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
力扣-二叉树的最大的深度
Opening - Open a new .NET modern application development experience
02 【开发服务器 资源模块】
SDC简介
QStyle平台风格
Access Characteristics of Constructor under Inheritance Relationship
C student management system Insert the student node at the specified location
J9数字货币论:web3的创作者经济是什么?
【 2 】 OpenCV image processing: basic knowledge of OpenCV
Apache DolphinScheduler, a new generation of distributed workflow task scheduling platform in practice - Medium
DAY23: Command Execution & Code Execution Vulnerability
解决connect: The requested address is not valid in its context
云原生(三十二) | Kubernetes篇之平台存储系统介绍
select 标签自定义样式
OpenGL 工作原理
解决端口占用问题 Port xxxx was already in use
Regular expression to match a certain string in the middle
Using OpenVINO to implement the flying paddle version of the PGNet inference program
What should I do if the self-incrementing id of online MySQL is exhausted?
Flink 1.15.1 集群搭建(StandaloneSession)

![[LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)](/img/ee/6b52072c841af99488dc0c1141c74c.png)







