当前位置: 首页 > news >正文

【Torch API】pytorch 中repeat_interleave函数详解

torch.repeat_interleave(inputrepeatsdim=None) → Tensor

Repeat elements of a tensor.

Parameters

  • input (Tensor) – the input tensor.

  • repeats (Tensor or int) – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.

  • dim (intoptional) – The dimension along which to repeat values. By default, use the flattened input array, and return a flat output array.

Returns

    Repeated tensor which has the same shape as input, except along the given axis.

>>> x = torch.tensor([1, 2, 3])
>>> x.repeat_interleave(2)
tensor([1, 1, 2, 2, 3, 3])
>>> y = torch.tensor([[1, 2], [3, 4]])
>>> torch.repeat_interleave(y, 2)
tensor([1, 1, 2, 2, 3, 3, 4, 4])
>>> torch.repeat_interleave(y, 3, dim=1)
tensor([[1, 1, 1, 2, 2, 2],[3, 3, 3, 4, 4, 4]])
>>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
tensor([[1, 2],[3, 4],[3, 4]])

torch.repeat_interleave(repeats) → Tensor

If the repeats is tensor([n1, n2, n3, …]), then the output will be tensor([0, 0, …, 1, 1, …, 2, 2, …, …]) where 0 appears n1 times, 1 appears n2 times, 2 appears n3 times, etc.

http://www.lryc.cn/news/145880.html

相关文章:

  • TDesign表单rules通过函数 实现复杂逻辑验证输入内容
  • springgateway网关修改响应后,部分中文乱码问题
  • 微信开发之一键发布群公告的技术实现
  • R语言和Python用泊松过程扩展:霍克斯过程Hawkes Processes分析比特币交易数据订单到达自激过程时间序列...
  • 自动化运维:Ansible脚本之playbook剧本
  • 基于角色访问控制-RBAC(Role-Based Access Control)
  • springboot项目实现断点续传
  • 解析经典面试题:for 循环中的 let var
  • CSS按钮-跑马灯边框
  • 【PCIE系统学习】Gen1/2Gen3/4 symobl与OrderSet概念对比
  • C++ Qt 中QMimeDatabase类详细介绍以及应用场景
  • 深度学习7:生成对抗网络 – Generative Adversarial Networks | GAN
  • R语言空气污染数据的地理空间可视化和分析:颗粒物2.5(PM2.5)和空气质量指数(AQI)...
  • 实现excel导出最简单方式
  • 【每日一题Day310】LC1654到家的最少跳跃次数 | BFS
  • [Android AIDL] --- AIDL原理简析
  • 企业的固定资产管理怎么操作
  • Rust 进阶学习
  • 保护网站安全:学习蓝莲花的安装和使用,复现跨站脚本攻击漏洞及XSS接收平台
  • Redis——如何解决redis穿透、雪崩、击穿问题
  • MySQL一行记录是如何存储的?
  • [element-ui] el-tree全部展开与收回
  • git 统计(命令)
  • 斐波那契1(矩阵快速幂加速递推,斐波那契前n项平方和)
  • minikube mac 启动
  • 从零开始学习 Java:简单易懂的入门指南之查找算法及排序算法(二十)
  • 非煤矿山风险监测预警算法 yolov8
  • Ansible学习笔记(一)
  • 2024毕业设计选题指南【附选题大全】
  • Error: PostCSS plugin autoprefixer requires PostCSS 8 问题解决办法