【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.

相关推荐
拾光拾趣录13 小时前
为什么选择 ReAct 模式而不是 Plan-and-Execute?
人工智能
武子康13 小时前
调查研究-196 CEO-Bench:Agent 不再只是“做任务“,而是要学会“经营一个系统“
人工智能
用户3299016750513 小时前
把AI返回的Markdown表格渲染成可排序表格
人工智能
还好还好不是吗13 小时前
MatrixMedia HTTP 发布接口:让 AI 工作流直接驱动多平台视频发布
人工智能
贵慜_Derek13 小时前
复杂系统没法一把梭重构:Semi-Autoresearch 怎么小步迁移还不掉功能
人工智能·agent·ai编程
ctxinf13 小时前
Vercel Eve 实际上手初探
人工智能
用户51914958484513 小时前
利用ShellcodePack实现DLL劫持与COM对象劫持技术详解
人工智能·aigc
武子康13 小时前
调查研究-195 从 AmEx 支付系统看 Cell-based Architecture:真正的高可用,不是无限重试,而是控制失败边界
人工智能·openai·agent
米小虾13 小时前
Prompt Engineering —— 意图的精确表达
人工智能·agent
荣码14 小时前
LangGraph多Agent协作:3个Agent干活比1个强,但我踩了4个坑
java·python