未验证 提交 7a00da9d 编写于 作者: W wangchaochaohu 提交者: GitHub

refine the doc for gather api test=develop (#2467)

上级 e9de0c9a
.. _api_tensor_cn_gather:
.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}`
!DO NOT EDIT THIS FILE MANUALLY!
.. _api_tensor_manipulation_gather:
gather
-------------------------------
:doc_source: paddle.fluid.layers.gather
--------
.. autofunction:: paddle.tensor.manipulation.gather
:noindex:
......@@ -8,7 +8,7 @@ gather
根据索引 ``index`` 获取输入(input)的最外层维度的条目,并将它们拼接在一起。
根据索引 ``index`` 获取输入 ``input`` 的最外层维度的条目,并将它们拼接在一起。
.. math::
......@@ -29,13 +29,15 @@ gather
参数:
- **input** (Variable) - 输入, 秩 ``rank >= 1`` , 支持的数据类型包括 int32、int64、float32、float64 和 uint8 (CPU)、float16(GPU) 。
- **index** (Variable) - 索引,秩 ``rank = 1``, 数据类型为 int32 或 int64。
- **input** (Tensor) - 输入, 秩 ``rank >= 1`` , 支持的数据类型包括 int32、int64、float32、float64 和 uint8 (CPU)、float16(GPU) 。
- **index** (Tensor) - 索引,秩 ``rank = 1``, 数据类型为 int32 或 int64。
- **overwrite** (bool) - 具有相同索引时在反向更新梯度的模式。如果为 ``True`` ,则使用覆盖模式更新相同索引的梯度;如果为 ``False`` ,则使用累积模式更新相同索引的梯度。默认值为 ``True`` 。
返回:和输入的秩相同的输出张量。
返回类型:Variable
抛出异常:
- ``TypeError``: - ``x`` 必须是Tensor 并且 ``x`` 的数据类型必须是uint8、float16、float32、float64、int32或者int64。
- ``TypeError``: - ``index`` 必须是Tensor并且数据类型必须是int32或者int64。
**代码示例**
......
......@@ -2,40 +2,50 @@
gather
-------------------------------
.. py:function:: paddle.tensor.gather(input, index, overwrite=True)
.. py:function:: paddle.gather(x, index, axis=None, name=None)
:alias_main: paddle.gather
:alias: paddle.gather,paddle.tensor.gather,paddle.tensor.manipulation.gather
:update_api: paddle.fluid.layers.gather
根据索引 index 获取输入 ``x`` 的指定 ``aixs`` 维度的条目,并将它们拼接在一起。
.. code-block:: text
X = [[1, 2],
[3, 4],
[5, 6]]
根据索引 index 获取输入(input)的最外层维度的条目,并将它们拼接在一起。
Index = [1, 2]
.. math::
axis = 0
Out=X[Index]
Then:
Out = [[3, 4],
[5, 6]]
**参数**:
- **input** (Variable) - 输入, 秩 ``rank >= 1`` , 支持的数据类型包括 int32、int64、float32、float64 和 uint8 (CPU)、float16(GPU) 。
- **index** (Variable) - 索引,秩 ``rank = 1``, 数据类型为 int32 或 int64。
- **overwrite** (bool) - 具有相同索引时在反向更新梯度的模式。如果为 ``True`` ,则使用覆盖模式更新相同索引的梯度;如果为 ``False`` ,则使用累积模式更新相同索引的梯度。默认值为 ``True`` 。
- **x** (Tensor) - 输入 Tensor, 秩 ``rank >= 1`` , 支持的数据类型包括 int32、int64、float32、float64 和 uint8 (CPU)、float16(GPU) 。
- **index** (Tensor) - 索引 Tensor,秩 ``rank = 1``, 数据类型为 int32 或 int64。
- **axis** (Tensor) - 指定index 获取输入的维度, ``axis`` 的类型可以是int或者Tensor,当 ``axis`` 为Tensor的时候其数据类型为int32 或者int64。
- **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
**返回**:和输入的秩相同的输出张量
**返回**:和输入的秩相同的输出Tensor
**返回类型**:Variable
抛出异常:
- ``TypeError``: - ``x`` 必须是Tensor 并且 ``x`` 的数据类型必须是uint8、float16、float32、float64、int32或者int64。
- ``TypeError``: - ``index`` 必须是Tensor并且数据类型必须是int32或者int64。
- ``TypeError``: - ``axis`` 必须是Tensor或者int, 当 ``axis`` 是Tensor的时候数据类型必须是int32或者int64。
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
with fluid.dygraph.guard():
input_1 = np.array([[1,2,3],[4,5,6],[7,8,9]])
index_1 = np.array([0,1])
input = fluid.dygraph.to_variable(input_1)
index = fluid.dygraph.to_variable(index_1)
output = paddle.fluid.layers.gather(input, index)
# expected output: [[1, 2, 3],[4, 5, 6]]
import paddle
paddle.disable_static()
input_1 = np.array([[1,2],[3,4],[5,6]])
index_1 = np.array([0,1])
input = paddle.to_tensor(input_1)
index = paddle.to_tensor(index_1)
output = paddle.gather(input, index, axis=0)
# expected output: [[1,2],[3,4]]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册