gather函数 python

Searching…

zhuanlan.zhihu.com

图解PyTorch中的torch.gather函数 - 知乎

上面的取值例子是 取单个值 或具 有逻辑顺序序列 的例子,而对于深度学习常用的 批量tensor 数据来说,我们的需求可能是选取其中 多个且乱序 的值,此时 gather() 就是一个很好的tool,它可以帮助我们从批量tensor中取出指定乱序索引下的数据,因此其用途如下

docs.pytorch.org

torch.gather — PyTorch 2.9 documentation

torch.gather # torch.gather(input, dim, index, *, sparse_grad=False, out=None) → Tensor # Gathers values along an axis specified by dim. For a 3-D tensor the output is specified by:

jishuzhan.net

Pytorch中gather ()函数详解和实战示例 - 技术栈

Jun 19, 2025 · 在 PyTorch 中,torch.gather () 是一个非常实用的张量操作函数,主要用于根据索引从输入张量中选择特定位置的值。 它常用于注意力机制、序列处理等场景。

zhuanlan.zhihu.com

如何理解 Pytorch 中的 gather 函数? - 知乎

现在, 我们就需要 gather函数。 gather函数有三个参数: input: 输入的 tensor dim: 收集值沿着的维度 index: 要从 特别地, input 和 index 的维度除了在 dim 维度外的其他维度需要相同。 例如, input 的形状是 4 \times 10 \times 15, dim 为 0, 那么 index 必须是 N \times 10 ...

blog.csdn.net

pytorch中的gather ()函数 - CSDN博客

Sep 16, 2025 · 本文通过实例详细介绍了PyTorch中gather函数的工作原理。 gather函数可根据指定索引从输入张量中选择元素,并以张量形式返回结果。 文章通过两个维度上的示例,帮助读者理解如何使用该函数。

www.geeksforgeeks.org

Understanding the Gather Function in PyTorch - GeeksforGeeks

Jul 23, 2025 · The gatherfunction in PyTorch is a powerful tool for selecting specific elements from a tensor based on indices. By understanding how it works and exploring practical examples, you can leverage this fun...

zhuanlan.zhihu.com

一图看懂torch.gather()函数用法 - 知乎

Oct 14, 2023 · 理解了以上张量对轴运算的基本框架后,就很容易理解torch.gather ()函数了。 图4演示了使用代码output = torch.gather (input, dim=0, index)取张量索引的过程。

blog.csdn.net

【pytorch函数】gather函数_python gather-CSDN博客

Jun 17, 2025 · 本文介绍了Pytorch中gather函数的用法,即a.gather (dim, index)。 其中dim是整数,指定在哪个维度上进行索引;index是与输入张量维度相同的张量,用于指定要收集的值的索引。 还给出了示例,解释了在二维张量中按列索引的具体操作。