当前位置:网站首页>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]])参考
边栏推荐
猜你喜欢

nodeJs--encapsulate routing
![01 [Foreword Basic Use Core Concepts]](/img/90/67537d5fad28d68766ca85b887839e.png)
01 [Foreword Basic Use Core Concepts]

C language diary 9 3 kinds of statements of if

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

Live preview | 30 minutes started quickly!Look at credible distributed AI chain oar architectural design

【解密】OpenSea免费创造的NFT都没上链竟能出现在我的钱包里?

Optimizing the feed flow encountered obstacles, who helped Baidu break the "memory wall"?

浅谈数据安全治理与隐私计算

C language implements a simple number guessing game

从零到一快速学会三子棋
随机推荐
Semi-Decentralized Federated Learning for Cooperative D2D Local Model Aggregation
leetcode 15
matlab绘制用颜色表示模值大小的箭头图
Gantt chart is here, project management artifact, template is used directly
云原生(三十二) | Kubernetes篇之平台存储系统介绍
散列表的查找(哈希表)
后期学习计划
02 【开发服务器 资源模块】
ARM Mailbox
常见的硬件延迟
Greenplum数据库故障分析——版本升级后gpstart -a为何返回失败
the mechanism of ideology
Flink 1.15.1 集群搭建(StandaloneSession)
sql语句多字段多个值如何进行排序
shell语句修改txt文件或者sh文件
View handler 踩坑记录
Greenplum Database Fault Analysis - Can a Soft Connection Be Made to the Database Base Folder?
C language diary 9 3 kinds of statements of if
SDC简介
Dotnet 6 Why does the network request not follow the change of the system network proxy and dynamically switch the proxy?