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 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],
#         [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]])

参考

torch.roll — PyTorch 1.12 documentation

torch.roll() 用法解读相关推荐

  1. torch.roll() 函数用法

    Pytorch 官方文档:https://pytorch.org/docs/master/generated/torch.roll.htmlhttps://pytorch.org/docs/maste ...

  2. torch.roll

    原理:将tensor进行偏移.例如[1,2,3]变成[2,3,1],这个就是roll.又再如[1,2,3]变成[3,1,2].前者向左偏移一个单位,后者向左偏移两个单位. 明白了原理就很简单了. to ...

  3. torch.stack(), torch.cat()用法详解

    torch.stack(), torch.cat()用法详解 if __name__ == '__main__':import torchx_dat = torch.tensor([[1, 2], [ ...

  4. torch.roll() 详解

    torch.roll(input, shifts, dims=None) input (Tensor) – the input tensor. shifts (int or tuple of pyth ...

  5. input标签用法解读

    HTML5/HTML中标签用法解读 OK!今天博主为小伙伴们介绍的内容是HTML5/HTML中标签的用法,,, ,emmm图文并茂哦! 下面正式开始内容的介绍:首先,直观上说标签规定了用户可以在其中输 ...

  6. 【torch】torch.roll

    torch.roll 张量滚动 1 torch.roll(input, shifts, dims=None) → Tensor input为输入张量 shift表示要滚动的幅度.负数表示左.上方向(二 ...

  7. torch.sort()用法

    torch.sort()用法 torch.sort(input, dim=- 1, descending=False, stable=False, out=None) 这个函数用于将输入的tensor ...

  8. torch.roll 函数的理解

    torch.roll 函数官方解释 如果是看swin-transformer进来的,推荐看看GitHub上的这个问题,会很有帮助! https://github.com/microsoft/Swin- ...

  9. torch.roll图片实验

    torch.roll(input, shifts, dims=None) → Tensor input为输入张量,shifts表示要滚动的方向.负数表示左上,正数表示右下.dims表示要滚动的维度. ...

最新文章

  1. 【ACM】nyoj_305_表达式求值_201308081018
  2. CSS中的三种样式来源:创作人员、读者和用户代理
  3. 音乐上传网站_国外最受欢迎的15个BT下载网站
  4. POJ 2115 模线性方程 ax=b(mod n)
  5. 检索召回 技术综述!
  6. Linux安装nextcloud教程,WSL下安装nextcloud
  7. java左移负数位_java的左移运算符和右移运算符
  8. Linux获取外部程序指针,Linux内核获取当前进程指针
  9. [Linux] sed编辑器
  10. MATLAB学习笔记————(MATLAB的矩阵及其操作②)
  11. C++有序map和无序unordered_map性能测试对比
  12. ykhmi是什么触摸屏软件_YKHMI 中达优控7寸一体机兼容台达ES2
  13. LIME-论文阅读笔记
  14. Hadoop之POC测试总结
  15. 安卓投屏神器scrcpy
  16. Html表格实现行上下移动
  17. ps存储计算机还是云文档,ps无法创建、保存云文档怎么办
  18. Java环境变量设置-Java
  19. oracle dbac安装,oracle rac环境修改db_files参数
  20. 用Python实现快速排序和冒泡排序,代码+详细解析

热门文章

  1. 在Windows XP中为Android 4.0设备安装MTP驱动程序
  2. 8. 设计模式 外观模式 一键电影模式
  3. RISC-V 和 Cortex-M 的异同
  4. 【大学物理学】静电场
  5. 翻译考试用计算机作答,上半年CATTI考试方式还是纸笔,下半年就实行全面机考?真是几家欢喜几家愁!...
  6. MySQL的背景、字体换色
  7. 日知录(15):记药盒的串口通信
  8. LC72 Edit Distance
  9. 数学建模(一)对变化进行建模及其解
  10. 情感分析的新方法,使用word2vec对微博文本进行情感分析和分类