未验证 提交 c3912ac2 编写于 作者: Y Yiqun Liu 提交者: GitHub

Update chinese doc of layers.sums. (#1234)

* Update chinese doc of layers.sums.
test=develop
test=document_preview

* Add more examples and more detail imformation of output.
test=develop
test=document_preview

* Refine the format.
test=develop
test=document_preview

* Refine the comment in example codes.
test=develop
test=document_preview

* Refine the introduce of out.
test=develop
test=document_preview

* Refine the introduction of out.
test=develop
test=document_preview
上级 35f5276e
......@@ -5,43 +5,50 @@ sums
.. py:function:: paddle.fluid.layers.sums(input,out=None)
函数对输入进行求和,并返回求和结果作为输出
OP计算多个输入Tensor逐个元素相加的和
参数:
- **input** (Variable|list)-输入张量,有需要求和的元素
- **out** (Variable|None)-输出参数。求和结果。默认:None
返回:输入的求和。和参数'out'等同
返回类型:变量(Variable)
**代码示例**:
- 示例:3个Tensor求和
.. code-block:: python
import paddle.fluid as fluid
# sum of several tensors
a0 = fluid.layers.fill_constant(shape=[1], dtype='int64', value=1)
a1 = fluid.layers.fill_constant(shape=[1], dtype='int64', value=2)
a2 = fluid.layers.fill_constant(shape=[1], dtype='int64', value=3)
sums = fluid.layers.sums(input=[a0, a1, a2])
输入:
x0.shape = [2, 3]
x0.data = [[1., 2., 3.],
[4., 5., 6.]]
x1.shape = [2, 3]
x1.data = [[10., 20., 30.],
[40., 50., 60.]]
x2.shape = [2, 3]
x2.data = [[100., 200., 300.],
[400., 500., 600.]]
# sum of a tensor array
array = fluid.layers.create_array('int64')
i = fluid.layers.zeros(shape=[1], dtype='int64', force_cpu=True)
fluid.layers.array_write(a0, array=array, i=i)
i = fluid.layers.increment(x=i)
fluid.layers.array_write(a1, array=array, i=i)
i = fluid.layers.increment(x=i)
fluid.layers.array_write(a2, array=array, i=i)
sums = fluid.layers.sums(input=array)
输出:
out.shape = [2, 3]
out.data = [[111., 222., 333.],
[444., 555., 666.]]
参数:
- **input** (list) - 多个维度相同的Tensor组成的元组。支持的数据类型:float32,float64,int32,int64。
- **out** (Variable,可选) - 指定求和的结果Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。
返回:输入的和,数据类型和维度与输入Tensor相同。若 ``out`` 为 ``None`` ,返回值是一个新的Variable;否则,返回值就是 ``out`` 。
返回类型:Variable
**代码示例**:
.. code-block:: python
import paddle.fluid as fluid
x0 = fluid.layers.fill_constant(shape=[16, 32], dtype='int64', value=1)
x1 = fluid.layers.fill_constant(shape=[16, 32], dtype='int64', value=2)
x2 = fluid.layers.fill_constant(shape=[16, 32], dtype='int64', value=3)
x3 = fluid.layers.fill_constant(shape=[16, 32], dtype='int64', value=0)
# 多个Tensor求和,结果保存在一个新建的Variable sum0,即sum0=x0+x1+x2,值为[[6, ..., 6], ..., [6, ..., 6]]
sum0 = fluid.layers.sums(input=[x0, x1, x2])
# 多个Tensor求和,sum1和x3是同一个Variable,相当于x3=x0+x1+x2,值为[[6, ..., 6], ..., [6, ..., 6]]
sum1 = fluid.layers.sums(input=[x0, x1, x2], out=x3)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册