当前位置:网站首页>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]])参考
边栏推荐
- C language diary 9 3 kinds of statements of if
- 散列表的查找(哈希表)
- leetcode 15
- 【MySQL系列】- LIKE查询 以%开头一定会让索引失效吗
- Opening - Open a new .NET modern application development experience
- 常见的硬件延迟
- Jincang database KingbaseES V8 GIS data migration solution (3. Data migration based on ArcGIS platform to KES)
- 甘特图来啦,项目管理神器,模板直接用
- 没有对象的程序员如何过七夕
- 树形查找(二叉查找树)
猜你喜欢

The 2022 EdgeX China Challenge will be grandly opened on August 3

View handler 踩坑记录

iNFTnews | 对体育行业和球迷来说,NFT可以带来什么?

LeetCode使用最小花费爬楼梯----dp问题

Intel XDC 2022 Wonderful Review: Build an Open Ecosystem and Unleash the Potential of "Infrastructure"

Go 微服务开发框架 DMicro 的设计思路

基于左序遍历的数据存储实践

HOG feature study notes

View handler stepping record

Jincang database KingbaseES V8 GIS data migration solution (3. Data migration based on ArcGIS platform to KES)
随机推荐
Jincang database KingbaseES V8 GIS data migration solution (3. Data migration based on ArcGIS platform to KES)
Introduction to SDC
[ROS] (10) ROS Communication - Service Communication
编译预处理等细节
The 2022 EdgeX China Challenge will be grandly opened on August 3
力扣-相同的树
Greenplum数据库故障分析——能对数据库base文件夹进行软连接嘛?
Domain Driven Design - MDD
海量服务实例动态化管理
What should I do if the self-incrementing id of online MySQL is exhausted?
select tag custom style
select 标签自定义样式
STM32使用stm32cubemx LL库系列教程
浅谈数据安全治理与隐私计算
LPQ(局部相位量化)学习笔记
leetcode-另一棵树的子树
Short domain name bypass and xss related knowledge
RAID disk array
C语言日记 9 if的3种语句
View handler stepping record