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

相关推荐
伊织code1 分钟前
LaTeX OCR - 数学公式识别系统
python·ai·ocr·latex·数学公式识别
声声codeGrandMaster3 小时前
Django之验证码功能
数据库·后端·python·django
BOB-wangbaohai4 小时前
LangChain4j入门AI(六)整合提示词(Prompt)
人工智能·prompt·springboot3.x·langchain4j
灬0灬灬0灬5 小时前
pytorch训练可视化工具---TensorBoard
人工智能·pytorch·深度学习
文火冰糖的硅基工坊5 小时前
[创业之路-369]:企业战略管理案例分析-9-战略制定-差距分析的案例之华为
人工智能·华为·架构·系统架构·跨学科·跨学科融合
平和男人杨争争6 小时前
山东大学计算机图形学期末复习15——CG15
人工智能·算法·计算机视觉·图形渲染
lucky_lyovo6 小时前
OpenCV图像边缘检测
人工智能·opencv·计算机视觉
佩奇的技术笔记6 小时前
Python入门手册:Python简介,什么是Python
开发语言·python
集和诚JHCTECH6 小时前
NODE-I916 & I721模块化电脑发布,AI算力与超低功耗的完美平衡
大数据·人工智能·电脑
恩喜玛生物6 小时前
深度学习实战 04:卷积神经网络之 VGG16 复现三(训练)
人工智能·深度学习·cnn