From 1750081162e9119a8a414f535bea72fabf4f7777 Mon Sep 17 00:00:00 2001 From: guofei <52460041+gfwm2013@users.noreply.github.com> Date: Mon, 24 Aug 2020 13:31:21 +0800 Subject: [PATCH] Add chinese and english documents of paddle.prod (#2413) * Add chinese and english documents of paddle.prod test=develop --- doc/fluid/api/tensor/math.rst | 1 + doc/fluid/api/tensor/math/prod.rst | 9 +++ doc/fluid/api_cn/layers_cn/reduce_prod_cn.rst | 2 +- doc/fluid/api_cn/tensor_cn.rst | 1 + doc/fluid/api_cn/tensor_cn/prod_cn.rst | 72 +++++++++++++++++++ 5 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 doc/fluid/api/tensor/math/prod.rst create mode 100644 doc/fluid/api_cn/tensor_cn/prod_cn.rst diff --git a/doc/fluid/api/tensor/math.rst b/doc/fluid/api/tensor/math.rst index 50d66eac8..f79e3e0de 100644 --- a/doc/fluid/api/tensor/math.rst +++ b/doc/fluid/api/tensor/math.rst @@ -23,6 +23,7 @@ math math/mm.rst math/mul.rst math/pow.rst + math/prod.rst math/sign.rst math/sin.rst math/sqrt.rst diff --git a/doc/fluid/api/tensor/math/prod.rst b/doc/fluid/api/tensor/math/prod.rst new file mode 100644 index 000000000..b5ced4643 --- /dev/null +++ b/doc/fluid/api/tensor/math/prod.rst @@ -0,0 +1,9 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! +.. _api_tensor_math_prod: + +prod +---- + +.. autofunction:: paddle.tensor.math.prod + :noindex: diff --git a/doc/fluid/api_cn/layers_cn/reduce_prod_cn.rst b/doc/fluid/api_cn/layers_cn/reduce_prod_cn.rst index a1b65ee1d..c0a11bc92 100644 --- a/doc/fluid/api_cn/layers_cn/reduce_prod_cn.rst +++ b/doc/fluid/api_cn/layers_cn/reduce_prod_cn.rst @@ -15,7 +15,7 @@ reduce_prod 参数: - **input** (Variable)- 输入变量为多维Tensor或LoDTensor,支持数据类型为float32,float64,int32,int64。 - - **dim** (list | int ,可选)- 求乘积运算的维度。如果为None,则计算所有元素的乘积并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。 + - **dim** (int|list|tuple ,可选)- 求乘积运算的维度。如果为None,则计算所有元素的乘积并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。 - **keep_dim** (bool)- 是否在输出Tensor中保留减小的维度。如 keep_dim 为true,否则结果张量的维度将比输入张量小,默认值为False。 - **name** (str , 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 diff --git a/doc/fluid/api_cn/tensor_cn.rst b/doc/fluid/api_cn/tensor_cn.rst index a7b4a8c96..e0892a402 100644 --- a/doc/fluid/api_cn/tensor_cn.rst +++ b/doc/fluid/api_cn/tensor_cn.rst @@ -110,6 +110,7 @@ paddle.tensor tensor_cn/ones_cn.rst tensor_cn/ones_like_cn.rst tensor_cn/pow_cn.rst + tensor_cn/prod_cn.rst tensor_cn/rand_cn.rst tensor_cn/randint_cn.rst tensor_cn/randn_cn.rst diff --git a/doc/fluid/api_cn/tensor_cn/prod_cn.rst b/doc/fluid/api_cn/tensor_cn/prod_cn.rst new file mode 100644 index 000000000..2956d7911 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/prod_cn.rst @@ -0,0 +1,72 @@ +.. _cn_api_tensor_cn_prod: + +prod +------------------------------- + +.. py:function:: paddle.prod(x, axis=None, keepdim=False, dtype=None, name=None) + + + +对指定维度上的Tensor元素进行求乘积运算,并输出相应的计算结果。 + +参数: + - **x** (Tensor) - 输入的 `Tensor` ,数据类型为:float32、float64、int32、int64。 + - **axis** (int|list|tuple,可选) - 求乘积运算的维度。如果是None,则计算所有元素的乘积并返回包含单个元素的Tensor,否则该参数必须在 :math:`[-x.ndim, x.ndim)` 范围内。如果 :math:`axis[i] < 0` ,则维度将变为 :math:`x.ndim + axis[i]` ,默认为None。 + - **keepdim** (bool,可选) - 是否在输出 `Tensor` 中保留减小的维度。如 `keepdim` 为True,否则结果张量的维度将比输入张量小,默认值为False。 + - **dtype** (str,可选) - 输出Tensor的数据类型,支持int32、int64、float32、float64。如果指定了该参数,那么在执行操作之前,输入Tensor将被转换为dtype类型. 这对于防止数据类型溢出非常有用。若参数为空,则输出变量的数据类型和输入变量相同,默认为:None。 + - **name** (str,可选)- 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 + +返回:指定axis上累乘的结果的Tensor。 + +抛出异常: + - :code:`ValueError`:``dtype`` 的数据类型不是float32、float64、int32或int64时。 + - :code:`ValueError`:``axis`` 的数据类型不是int、list或tuple时 + +**代码示例**: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + + # the axis is a int element + data_x = np.array([[0.2, 0.3, 0.5, 0.9], + [0.1, 0.2, 0.6, 0.7]]).astype(np.float32) + x = paddle.to_tensor(data_x) + out1 = paddle.prod(x) + print(out1.numpy()) + # [0.0002268] + + out2 = paddle.prod(x, -1) + print(out2.numpy()) + # [0.027 0.0084] + + out3 = paddle.prod(x, 0) + print(out3.numpy()) + # [0.02 0.06 0.3 0.63] + print(out3.numpy().dtype) + # float32 + + out4 = paddle.prod(x, 0, keepdim=True) + print(out4.numpy()) + # [[0.02 0.06 0.3 0.63]] + + out5 = paddle.prod(x, 0, dtype='int64') + print(out5.numpy()) + # [0 0 0 0] + print(out5.numpy().dtype) + # int64 + + # the axis is list + data_y = np.array([[[1.0, 2.0], [3.0, 4.0]], + [[5.0, 6.0], [7.0, 8.0]]]) + y = paddle.to_tensor(data_y) + out6 = paddle.prod(y, [0, 1]) + print(out6.numpy()) + # [105. 384.] + + out7 = paddle.prod(y, (1, 2)) + print(out7.numpy()) + # [ 24. 1680.] -- GitLab