【Torch API】pytorch 中repeat_interleave函数详解

torch.``repeat_interleave(input , repeats , dim=None) → Tensor

Repeat elements of a tensor.

Parameters

  • input (Tensor) -- the input tensor.

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

  • dim (int, optional) -- 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.

相关推荐
Zzj_tju2 分钟前
混合检索为什么有效:RRF 改变了哪些排名?——SciFact 开发集冻结排名实验
人工智能·深度学习·语言模型
2601_962381133 分钟前
历史视频朝代更替动效怎么做?把 AE 关键帧换成 AI 分镜动画的实战拆解
人工智能·nginx·音视频
AI创界者8 分钟前
【AI音视频处理】AI视频 480p 一键修复到 1080p!FlashVSR + SeedVR2 本地超分整合包(Base免安装版)
人工智能·aigc·音视频
moxiaoran575317 分钟前
Codex接入MCP
人工智能
天远Date Lab21 分钟前
微服务架构实战:基于天远学历信息高级版构建自动化人才准入网关
人工智能·微服务·架构·自动化
small_wh1te_coder26 分钟前
字节技术总监30讲 AI课:3概率、信息论与损失函数|从Logits到Cross-Entropy带你吃透大模型训练
人工智能
云表无代码开发28 分钟前
日本开发者彻底破防:中文太强了!换成英文直接裂开
大数据·服务器·人工智能·microsoft·信息可视化
致Great40 分钟前
不止自动写论文!谷歌 ScientistTwo 让 AI 自己做实验、补消融、回审稿
人工智能·深度学习·机器学习
XMAIPC_Robot40 分钟前
CODESYS 实时控制 + RK182X 大模型算力扩展|RK3576 工业边缘控制器设计
人工智能·fpga开发·机器人·rk3588+fpga
迪飞特科技43 分钟前
【无标题】
android·人工智能·本地化大模型