当前位置:网站首页>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]])参考
边栏推荐
- Simple implementation of YOLOv7 pre-training model deployment based on OpenVINO toolkit
- HOG特征学习笔记
- .Net C# 控制台 使用 Win32 API 创建一个窗口
- 【OpenCV 图像处理2】:OpenCV 基础知识
- C学生管理系统 指定位置插入学生节点
- Access Characteristics of Constructor under Inheritance Relationship
- 亚马逊云科技 + 英特尔 + 中科创达为行业客户构建 AIoT 平台
- iNFTnews | What can NFTs bring to the sports industry and fans?
- [Decryption] Can the NFTs created by OpenSea for free appear in my wallet without being chained?
- 蚁剑高级模块开发
猜你喜欢

Simple implementation of YOLOv7 pre-training model deployment based on OpenVINO toolkit

View handler stepping record

Quickly learn chess from zero to one

lua学习

select 标签自定义样式

DAY22:sqli-labs 靶场通关wp(Less01~~Less20)

2022-08-04: Input: deduplicated array arr, the numbers in it only contain 0~9.limit, a number.Return: The maximum number that can be spelled out with arr if the requirement is smaller than limit.from

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

海量服务实例动态化管理

【OpenCV 图像处理2】:OpenCV 基础知识
随机推荐
Matlab map with color representation module value size arrow
C student management system Find student nodes based on student ID
SuperMap支持的国产环境汇总
Programmer's list of sheep counting when insomnia | Daily anecdote
继承关系下构造方法的访问特点
01 [Foreword Basic Use Core Concepts]
What should I do if the self-incrementing id of online MySQL is exhausted?
[机缘参悟-60]:《兵者,诡道也》-2-孙子兵法解读
[Fortune-telling-60]: "The Soldier, the Tricky Way"-2-Interpretation of Sun Tzu's Art of War
KingbaseES V8 GIS data migration solution (2. Introduction to the capabilities of Kingbase GIS)
Solve connect: The requested address is not valid in its context
亚马逊云科技携手中科创达为行业客户构建AIoT平台
[Decryption] Can the NFTs created by OpenSea for free appear in my wallet without being chained?
没有对象的程序员如何过七夕
leetcode-对称二叉树
Industry case | insurance companies of the world's top 500 construction standards can be used to drive the business analysis system
直播预告|30分钟快速入门!来看可信分布式AI链桨的架构设计
[LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)
How to simply implement the quantization and compression of the model based on the OpenVINO POT tool
浅谈数据安全治理与隐私计算