【Torch API】pytorch 中repeat_interleave函数详解

这篇具有很好参考价值的文章主要介绍了【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.文章来源地址https://www.toymoban.com/news/detail-682154.html

到了这里,关于【Torch API】pytorch 中repeat_interleave函数详解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Pytorch函数——torch.gather详解

    在学习强化学习时,顺便复习复习pytorch的基本内容,遇到了 torch.gather() 函数,参考图解PyTorch中的torch.gather函数 - 知乎 (zhihu.com)进行解释。 pytorch官网对函数给出的解释: 即input是一个矩阵,根据dim的值,将index的值替换到不同的维度的 索引 ,当dim为0时,index替代i的值,成为

    2024年01月18日
    浏览(30)
  • 【Pytorch】torch.max() 函数详解

    参数: input (Tensor) – 输入张量 返回输入张量所有元素中的最大值。 输出结果: 返回张量 input 在压缩指定维度 dim 时的最大值及其下标。 输出结果: 返回两张量 input 和 other_input 在对应位置上的最大值形成的新张量。 输出结果: 详解 torch.max 函数

    2024年01月23日
    浏览(38)
  • 笔记68:Pytorch中repeat函数的用法

    repeat 相当于一个broadcasting的机制 repeat(*sizes) 沿着指定的维度重复tensor。不同与expand(),本函数复制的是tensor中的数据。 转自:pytorch repeat的用法-CSDN博客

    2024年02月05日
    浏览(27)
  • 【pytorch】torch.gather()函数

    2024年02月06日
    浏览(31)
  • 深入浅出PyTorch函数torch.rand与torch.randn

    torch.rand 和 torch.randn 都是PyTorch中用于生成随机张量的函数,但它们生成随机数的方式有所不同。 torch.rand 生成在区间 [0, 1) 内均匀分布的随机数。 size 参数是一个表示所需张量形状的元组或整数。可以生成任何形状的随机张量。 torch.randn 生成从标准正态分布(均值为0,标准

    2024年02月09日
    浏览(29)
  • 举例说明PyTorch函数torch.cat与torch.stack的区别

    torch.cat 用于在 给定的维度 上连接多个张量,它将这些张量沿着指定维度堆叠在一起。 torch.stack 用于在 新的维度 上堆叠多个张量,它会创建一个新的维度,并将这些张量沿着这个新维度堆叠在一起。 Example1: Example1: Example2:

    2024年02月09日
    浏览(31)
  • 小白学Pytorch系列--Torch.optim API Base class(1)

    torch.optim是一个实现各种优化算法的包。大多数常用的方法都已得到支持,而且接口足够通用,因此将来还可以轻松集成更复杂的方法。 使用手torch.optim您必须构造一个优化器对象,该对象将保存当前状态,并将根据计算出的梯度更新参数。 要构造一个优化器,你必须给它一

    2023年04月13日
    浏览(22)
  • 小白学Pytorch系列--Torch.nn API Vision Layers(15)

    方法 注释 nn.PixelShuffle 将形状张量 ( ∗ , C r 2 , H , W ) (*,C r^2,H,W) ( ∗ , C r 2 , H , W ) 中的元素重新排列为形状张量 ( ∗ , C , H r , W r ) (*,C,H r,W r) ( ∗ , C , Hr , W r ) ,其中r是一个高阶因子。 nn.PixelUnshuffle 通过将形状张量 ( ∗ , C , H r , W r ) (*,C,H r,W r) ( ∗ , C , Hr , W r

    2023年04月22日
    浏览(27)
  • 深入浅出Pytorch函数——torch.zeros

    分类目录:《深入浅出Pytorch函数》总目录 相关文章: · 深入浅出Pytorch函数——torch.Tensor · 深入浅出Pytorch函数——torch.ones · 深入浅出Pytorch函数——torch.zeros · 深入浅出Pytorch函数——torch.full · 深入浅出Pytorch函数——torch.ones_like · 深入浅出Pytorch函数——torch.zeros_like · 深

    2024年02月07日
    浏览(45)
  • 深入浅出Pytorch函数——torch.tensor

    分类目录:《深入浅出Pytorch函数》总目录 相关文章: · 深入浅出TensorFlow2函数——tf.constant · 深入浅出Pytorch函数——torch.tensor · 深入浅出Pytorch函数——torch.as_tensor · 深入浅出Pytorch函数——torch.Tensor · 深入浅出PaddlePaddle函数——paddle.to_tensor 基于 data 构建一个没有梯度历史

    2024年02月04日
    浏览(85)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包