Skip to content

Commit

Permalink
refine the cn fill_constant doc test=develop (PaddlePaddle#1902)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangchaochaohu authored Mar 12, 2020
1 parent 16836d4 commit 3695adc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion doc/fluid/api_cn/layers_cn/fill_constant_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fill_constant
创建的Tensor的stop_gradient属性默认为True。

参数:
- **shape** (tuple|list)- 创建Tensor的形状
- **shape** (tuple|list|Variable)- 要创建的LoDTensor或者SelectedRows的形状。 数据类型为int32或int64。 如果shape是一个列表或元组,则其元素应该是形状为[1]的整数或Tensor。 如果shape是Variable,则它应该是一维Tensor
- **dtype** (np.dtype|core.VarDesc.VarType|str)- 创建LoDTensor或者SelectedRows的数据类型,支持数据类型为float16, float32, float64, int32, int64。
- **value** (float|int)- 用于初始化输出LoDTensor或者SelectedRows的常量数据的值。
- **force_cpu** (bool)- 用于标志LoDTensor或者SelectedRows是否创建在CPU上,默认值为False,若设为true,则数据必须在CPU上。
Expand All @@ -21,6 +21,9 @@ fill_constant

返回类型:变量(Variable)

抛出异常:
- :code:`TypeError`: dtype必须是bool,float16,float32,float64,int32和int64之一,并且输出Tensor的数据类型必须与dtype相同。

**代码示例**:

.. code-block:: python
Expand All @@ -29,3 +32,11 @@ fill_constant
data1 = fluid.layers.fill_constant(shape=[2,1], value=0, dtype='int64') #data1=[[0],[0]]
data2 = fluid.layers.fill_constant(shape=[2,1], value=5, dtype='int64', out=data1)
#data1=[[5],[5]] data2=[[5],[5]]
# attr shape is a list which contains Variable Tensor.
positive_2 = fluid.layers.fill_constant([1], "int32", 2)
data3 = fluid.layers.fill_constant(shape=[1, positive_2], dtype='float32', value=1.5) # data3=[1.5, 1.5]
# attr shape is an Variable Tensor.
shape = fluid.layers.fill_constant([1,2], "int32", 2) # shape=[2,2]
data4 = fluid.layers.fill_constant(shape=shape, dtype='bool', value=True) # data4=[[True,True],[True,True]]

0 comments on commit 3695adc

Please sign in to comment.