From 012b4786efea4f4d6c033b51ffc92c5753026c9a Mon Sep 17 00:00:00 2001 From: lilong12 Date: Sat, 22 Aug 2020 12:49:06 +0800 Subject: [PATCH] add the chinese doc for expand and expand_as (#2438) * modify the doc, test=develop --- doc/fluid/api_cn/paddle_cn/expand_as_cn.rst | 2 +- doc/fluid/api_cn/paddle_cn/expand_cn.rst | 2 +- doc/fluid/api_cn/tensor_cn/expand_as_cn.rst | 35 +++++++++++++++++++-- doc/fluid/api_cn/tensor_cn/expand_cn.rst | 33 +++++++++++++++++-- 4 files changed, 66 insertions(+), 6 deletions(-) diff --git a/doc/fluid/api_cn/paddle_cn/expand_as_cn.rst b/doc/fluid/api_cn/paddle_cn/expand_as_cn.rst index a5615e16b..448bb6afb 100644 --- a/doc/fluid/api_cn/paddle_cn/expand_as_cn.rst +++ b/doc/fluid/api_cn/paddle_cn/expand_as_cn.rst @@ -2,6 +2,6 @@ expand_as ------------------------------- -:doc_source: paddle.fluid.layers.expand_as +:doc_source: paddle.tensor.expand_as diff --git a/doc/fluid/api_cn/paddle_cn/expand_cn.rst b/doc/fluid/api_cn/paddle_cn/expand_cn.rst index addb87a5a..cdff8439e 100644 --- a/doc/fluid/api_cn/paddle_cn/expand_cn.rst +++ b/doc/fluid/api_cn/paddle_cn/expand_cn.rst @@ -2,6 +2,6 @@ expand ------------------------------- -:doc_source: paddle.fluid.layers.expand +:doc_source: paddle.tensor.expand diff --git a/doc/fluid/api_cn/tensor_cn/expand_as_cn.rst b/doc/fluid/api_cn/tensor_cn/expand_as_cn.rst index ab63e99bb..2f62f6723 100644 --- a/doc/fluid/api_cn/tensor_cn/expand_as_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/expand_as_cn.rst @@ -1,7 +1,38 @@ -.. _cn_api_tensor_cn_expand_as: +.. _cn_api_tensor_expand_as: expand_as ------------------------------- -:doc_source: paddle.fluid.layers.expand_as +.. py:function:: paddle.expand_as(x, y, name=None) + +根据 ``y`` 的形状扩展 ``x`` ,扩展后, ``x`` 的形状和 ``y`` 的形状相同。 + +``x`` 的维数和 ``y`` 的维数应小于等于6,并且 ``y`` 的维数应该大于等于 ``x`` 的维数。扩展的维度的维度值应该为1。 + +参数 +::::::::: + - x (Tensor) - 输入的Tensor,数据类型为:bool、float32、float64、int32或int64。 + - y (Tensor) - 给定输入 ``x`` 扩展后的形状。 + - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +``Tensor`` ,数据类型与 ``x`` 相同。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + np_data_x = np.array([1, 2, 3]).astype('int32') + np_data_y = np.array([[1, 2, 3], [4, 5, 6]]).astype('int32') + data_x = paddle.to_tensor(np_data_x) + data_y = paddle.to_tensor(np_data_y) + out = paddle.expand_as(data_x, data_y) + np_out = out.numpy() + # [[1, 2, 3], [1, 2, 3]] diff --git a/doc/fluid/api_cn/tensor_cn/expand_cn.rst b/doc/fluid/api_cn/tensor_cn/expand_cn.rst index 5a9ae8cba..94af4e93f 100644 --- a/doc/fluid/api_cn/tensor_cn/expand_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/expand_cn.rst @@ -1,7 +1,36 @@ -.. _cn_api_tensor_cn_expand: +.. _cn_api_tensor_expand: expand ------------------------------- -:doc_source: paddle.fluid.layers.expand +.. py:function:: paddle.expand(x, shape, name=None) + +根据 ``shape`` 指定的形状扩展 ``x`` ,扩展后, ``x`` 的形状和 ``shape`` 指定的形状一致。 + +``x`` 的维数和 ``shape`` 的元素数应小于等于6,并且 ``shape`` 中的元素数应该大于等于 ``x`` 的维数。扩展的维度的维度值应该为1。 + +参数 +::::::::: + - x (Tensor) - 输入的Tensor,数据类型为:bool、float32、float64、int32或int64。 + - shape (tuple|list|Tensor) - 给定输入 ``x`` 扩展后的形状,若 ``shape`` 为list或者tuple,则其中的元素值应该为整数或者1-D Tensor,若 ``shape`` 类型为Tensor,则其应该为1-D Tensor。 + - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回 +::::::::: +``Tensor`` ,数据类型与 ``x`` 相同。 + +代码示例 +::::::::: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + np_data = np.array([1, 2, 3]).astype('int32') + data = paddle.to_tensor(np_data) + out = paddle.expand(data, [2, 3]) + np_out = out.numpy() + # [[1, 2, 3], [1, 2, 3]] -- GitLab