当前位置:网站首页>torch.roll()
torch.roll()
2022-08-05 02:32:00 【00000cj】
torch.roll(input, shifts, dims=None) -> Tensor
定义
沿给定维度滚动张量输入。超出最后一个位置的元素在第一个位置重新引入。如果 dims 为 None,则张量将在滚动前被展平,然后恢复到原始形状。
参数
- input (Tensor) - 输入张量
- shifts (int or tuple of python: ints) - 张量元素移动的位置数。如果 shifts 是元组,则 dims 必须是大小相同的元组,每个维度都会滚动对应的值
- dims (int or tuple of python: ints) - 沿着dims指定的维度进行滚动
示例
import torch
x = 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],
# [2, 3],
# [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],
# [2, 1],
# [4, 3]])
参考
边栏推荐
- leetcode-对称二叉树
- 树表的查找
- The 20th day of the special assault version of the sword offer
- ARM Mailbox
- View handler 踩坑记录
- “嘀哩哩,等灯等灯”,工厂安全生产的提示音
- Flink 1.15.1 集群搭建(StandaloneSession)
- 解决connect: The requested address is not valid in its context
- C language diary 9 3 kinds of statements of if
- Semi-Decentralized Federated Learning for Cooperative D2D Local Model Aggregation
猜你喜欢
正则表达式,匹配中间的某一段字符串
在这个超连接的世界里,你的数据安全吗
树表的查找
01 【前言 基础使用 核心概念】
多线程(2)
【genius_platform软件平台开发】第七十六讲:vs预处理器定义的牛逼写法!!!!(其他组牛逼conding人员告知这么配置来取消宏定义)
Regular expression to match a certain string in the middle
Intel XDC 2022 Wonderful Review: Build an Open Ecosystem and Unleash the Potential of "Infrastructure"
Live preview | 30 minutes started quickly!Look at credible distributed AI chain oar architectural design
shell语句修改txt文件或者sh文件
随机推荐
Hypervisor related knowledge points
甘特图来啦,项目管理神器,模板直接用
the mechanism of ideology
基于OpenVINO工具套件简单实现YOLOv7预训练模型的部署
Common hardware delays
DAY22:sqli-labs 靶场通关wp(Less01~~Less20)
“嘀哩哩,等灯等灯”,工厂安全生产的提示音
nodeJs--封装路由
常见的硬件延迟
回顾51单片机
特殊矩阵的压缩存储
Greenplum Database Fault Analysis - Can a Soft Connection Be Made to the Database Base Folder?
如何逐步执行数据风险评估
[ROS] (10) ROS Communication - Service Communication
解决connect: The requested address is not valid in its context
Greenplum数据库故障分析——能对数据库base文件夹进行软连接嘛?
KingbaseES V8 GIS data migration solution (2. Introduction to the capabilities of Kingbase GIS)
02 [Development Server Resource Module]
亚马逊云科技 + 英特尔 + 中科创达为行业客户构建 AIoT 平台
.Net C# 控制台 使用 Win32 API 创建一个窗口