Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
FluidDoc
提交
2b4be2e2
F
FluidDoc
项目概览
PaddlePaddle
/
FluidDoc
通知
10
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
23
列表
看板
标记
里程碑
合并请求
111
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
FluidDoc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
23
Issue
23
列表
看板
标记
里程碑
合并请求
111
合并请求
111
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
2b4be2e2
编写于
7月 17, 2020
作者:
W
wangchaochaohu
提交者:
GitHub
7月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Doc refine for API 2.0 (#2291)
上级
2d51daba
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
89 addition
and
69 deletion
+89
-69
doc/fluid/api_cn/layers_cn/fill_constant_cn.rst
doc/fluid/api_cn/layers_cn/fill_constant_cn.rst
+2
-1
doc/fluid/api_cn/tensor_cn/full_cn.rst
doc/fluid/api_cn/tensor_cn/full_cn.rst
+19
-16
doc/fluid/api_cn/tensor_cn/full_like_cn.rst
doc/fluid/api_cn/tensor_cn/full_like_cn.rst
+14
-17
doc/fluid/api_cn/tensor_cn/index_select_cn.rst
doc/fluid/api_cn/tensor_cn/index_select_cn.rst
+26
-24
doc/fluid/api_cn/tensor_cn/linspace_cn.rst
doc/fluid/api_cn/tensor_cn/linspace_cn.rst
+7
-4
doc/fluid/api_cn/tensor_cn/ones_cn.rst
doc/fluid/api_cn/tensor_cn/ones_cn.rst
+21
-7
未找到文件。
doc/fluid/api_cn/layers_cn/fill_constant_cn.rst
浏览文件 @
2b4be2e2
...
...
@@ -28,7 +28,8 @@ fill_constant
返回类型:变量(Variable)
抛出异常:
- :code:`TypeError`: dtype必须是bool,float16,float32,float64,int32和int64之一,并且输出Tensor的数据类型必须与dtype相同。
- :code:`TypeError`: dtype必须是bool,float16,float32,float64,int32和int64之一,输出Tensor的数据类型必须与dtype相同。
- :code:`TypeError`: 当 `shape` 的数据类型不是list、tuple、Variable。
**代码示例**:
...
...
doc/fluid/api_cn/tensor_cn/full_cn.rst
浏览文件 @
2b4be2e2
...
...
@@ -3,7 +3,7 @@
full
-------------------------------
.. py:function:: paddle.full(shape, fill_value,
out=None, dtype=None, device=None, stop_gradient=Tru
e, name=None)
.. py:function:: paddle.full(shape, fill_value,
dtype=Non
e, name=None)
:alias_main: paddle.full
:alias: paddle.full,paddle.tensor.full,paddle.tensor.creation.full
...
...
@@ -14,12 +14,9 @@ full
该OP创建一个和具有相同的形状和数据类型的Tensor,其中元素值均为fill_value。
参数:
- **shape** (list|tuple|Variable) – 指定创建Tensor的形状(shape)。
- **fill_value** (bool|float16|float32|int32|int64|Variable) - 用于初始化输出Tensor的常量数据的值。默认为0。注意:该参数不可超过输出变量数据类型的表示范围。
- **out** (Variable,可选) - 输出Tensor。如果为None,则创建一个新的Tensor作为输出Tensor,默认值为None。
- **shape** (list|tuple|Variable) – 指定创建Tensor的形状(shape), 数据类型为int32 或者int64。
- **fill_value** (bool|float|int|Variable) - 用于初始化输出Tensor的常量数据的值。注意:该参数不可超过输出变量数据类型的表示范围。
- **dtype** (np.dtype|core.VarDesc.VarType|str, 可选)- 输出变量的数据类型。若参数为空,则输出变量的数据类型和输入变量相同,默认值为None。
- **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。
- **stop_gradient** (bool,可选) – 是否从此 Variable 开始,之前的相关部分都停止梯度计算,默认为True。
- **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:返回一个存储结果的Tensor。
...
...
@@ -28,7 +25,6 @@ full
抛出异常:
- ``TypeError`` - 如果 ``dtype`` 的类型不是bool, float16, float32, float64, int32, int64其中之一。
- ``TypeError`` - 如果 ``out`` 的元素的类型不是Variable。
- ``TypeError`` - 如果 ``shape`` 的类型不是list或tuple或Varibable。
**代码示例**:
...
...
@@ -37,17 +33,24 @@ full
import paddle
data1 = paddle.full(shape=[2,1], fill_value=0, dtype='int64') # data1=[[0],[0]]
data2 = paddle.full(shape=[2,1], fill_value=5, dtype='int64', device='gpu') # data2=[[5],[5]]
paddle.enable_imperative() # Now we are in imperative mode
data1 = paddle.full(shape=[2,1], fill_value=0, dtype='int64')
#[[0]
# [0]]
# attr shape is a list which contains Variable Tensor.
positive_2 = paddle.fill_constant([1], "int32", 2)
data3 = paddle.full(shape=[1, positive_2], dtype='float32', fill_value=1.5) # data3=[1.5, 1.5]
positive_3 = paddle.fill_constant([1], "int32", 2)
data3 = paddle.full(shape=[1, positive_2], dtype='float32', fill_value=1.5)
# [[1.5 1.5]]
# attr shape is an Variable Tensor.
shape = paddle.fill_constant([1,2], "int32", 2) # shape=[2,2]
data4 = paddle.full(shape=shape, dtype='bool', fill_value=True) # data4=[[True,True],[True,True]]
shape = paddle.fill_constant([2], "int32", 2)
data4 = paddle.full(shape=shape, dtype='bool', fill_value=True)
# [[True True]
# [True True]]
# attr value is an Variable Tensor.
val = paddle.fill_constant([1], "float32", 2.0) # val=[2.0]
data5 = paddle.full(shape=[2,1], fill_value=val, dtype='float32') #data5=[[2.0],[2.0]]
val = paddle.fill_constant([1], "float32", 2.0)
data5 = paddle.full(shape=[2,1], fill_value=val, dtype='float32') i
# [[2.0]
# [2.0]]
doc/fluid/api_cn/tensor_cn/full_like_cn.rst
浏览文件 @
2b4be2e2
...
...
@@ -3,40 +3,37 @@
full_like
-------------------------------
.. py:function:: paddle.full_like(
input, fill_value, out=None, dtype=None, device=None, stop_gradient=Tru
e, name=None)
.. py:function:: paddle.full_like(
x, fill_value, dtype=Non
e, name=None)
:alias_main: paddle.full_like
:alias: paddle.full_like,paddle.tensor.full_like,paddle.tensor.creation.full_like
该OP创建一个和input具有相同的形状和数据类型的Tensor,其中元素值均为fill_value。
参数:
- **input** (Variable) – 指定输入为一个多维的Tensor,数据类型可以是bool,float16,float32,float64,int32,int64。
- **fill_value** (bool|float|int) - 用于初始化输出Tensor的常量数据的值。默认为0。注意:该参数不可超过输出变量数据类型的表示范围。
- **out** (Variable,可选) - 输出Tensor。如果为None,则创建一个新的Tensor作为输出Tensor,默认值为None。
- **dtype** (np.dtype|core.VarDesc.VarType|str, 可选)- 输出变量的数据类型。若参数为空,则输出变量的数据类型和输入变量相同,默认值为None。
- **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。
- **stop_gradient** (bool,可选) – 是否从此 Variable 开始,之前的相关部分都停止梯度计算,默认为True。
- **x** (Variable) – 指定输入为一个多维的Tensor,数据类型可以是bool,float16,float32,float64,int32,int64。
- **fill_value** (bool|float|int) - 用于初始化输出Tensor的常量数据的值。注意:该参数不可超过输出变量数据类型的表示范围。
- **dtype** (np.dtype|core.VarDesc.VarType|str, 可选)- 输出变量的数据类型。若参数为None,则输出变量的数据类型和输入变量相同,默认值为None。
- **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:返回一个存储结果的Tensor。
返回类型:Variable
**代码示例**:
抛出异常:
- ``TypeError`` - 当dtype不是bool、float16、float32、float64、int32、int64其中之一。
- ``TypeError`` - 如果 ``shape`` 的类型不是list或tuple或Varibable。
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
input = fluid.data(name='input', dtype='float32', shape=[2, 3])
paddle.enable_imperative() # Now we are in imperative mode
input = paddle.full(shape=[2, 3], fill_value=0.0, dtype='float32', name='input')
output = paddle.full_like(input, 2.0)
exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())
img=np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)
res = exe.run(fluid.default_main_program(), feed={'input':img}, fetch_list=[output])
print(res) # [array([[2., 2., 2.], [2., 2., 2.]], dtype=float32)]
# [[2. 2. 2.]
# [2. 2. 2.]]
doc/fluid/api_cn/tensor_cn/index_select_cn.rst
浏览文件 @
2b4be2e2
...
...
@@ -3,48 +3,50 @@
index_select
-------------------------------
.. py:function:: paddle.index_select(
input, index, dim=0
)
.. py:function:: paddle.index_select(
x, index, axis=0, name=None
)
:alias_main: paddle.index_select
:alias: paddle.index_select,paddle.tensor.index_select,paddle.tensor.search.index_select
该OP沿着指定维度 ``
dim`` 对输入 ``input`` 进行索引,取 ``index`` 中指定的相应项,然后返回到一个新的张量。这里 ``index`` 是一个 ``1-D`` 张量。除 ``dim`` 维外,返回的张量其余维度大小同输入 ``input`` , ``dim
`` 维大小等于 ``index`` 的大小。
该OP沿着指定维度 ``
axis`` 对输入 ``input`` 进行索引,取 ``index`` 中指定的相应项,然后返回到一个新的张量。这里 ``index`` 是一个 ``1-D`` 张量。除 ``axis`` 维外,返回的张量其余维度大小同输入 ``input`` , ``axis
`` 维大小等于 ``index`` 的大小。
**参数**:
- **
input** (Variable)– 输入张量
。
- **
x** (Variable)– 输入张量。x的数据类型可以是float32,float64,int32,int64
。
- **index** (Variable)– 包含索引下标的一维张量。
- **dim** (int, optional) – 索引轴,若未指定,则默认选取第一维。
- **axis** (int, optional) – 索引轴,若未指定,则默认选取第0维。
- **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
**返回**:
-**Variable**
,
数据类型同输入。
-**Variable**
:
数据类型同输入。
抛出异常:
- ``TypeError`` - 当x或者index的类型不是Variable。
- ``TypeError`` - 当x的数据类型不是float32、float64、int32、int64其中之一或者index的数据类型不是int32、int64其中之一。
**代码示例**:
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
paddle.enable_imperative() # Now we are in imperative mode
data = np.array([[1.0, 2.0, 3.0, 4.0],
[5.0, 6.0, 7.0, 8.0],
[9.0, 10.0, 11.0, 12.0]])
data_index = np.array([0, 1, 1]).astype('int32')
with fluid.dygraph.guard():
x = fluid.dygraph.to_variable(data)
index = fluid.dygraph.to_variable(data_index)
out_z1 = paddle.index_select(x, index)
print(out_z1.numpy())
#[[1. 2. 3. 4.]
# [5. 6. 7. 8.]
# [5. 6. 7. 8.]]
out_z2 = paddle.index_select(x, index, dim=1)
print(out_z2.numpy())
#[[ 1. 2. 2.]
# [ 5. 6. 6.]
# [ 9. 10. 10.]]
[5.0, 6.0, 7.0, 8.0],
[9.0, 10.0, 11.0, 12.0]])
data_index = np.array([-1, 1, 1]).astype('int32')
x = paddle.imperative.to_variable(data)
index = paddle.imperative.to_variable(data_index)
out_z1 = paddle.index_select(x=x, index=index)
#[[1. 2. 3. 4.]
# [5. 6. 7. 8.]
# [5. 6. 7. 8.]]
out_z2 = paddle.index_select(x=x, index=index, axis=1)
#[[ 1. 2. 2.]
# [ 5. 6. 6.]
# [ 9. 10. 10.]]
doc/fluid/api_cn/tensor_cn/linspace_cn.rst
浏览文件 @
2b4be2e2
...
...
@@ -3,7 +3,7 @@
linspace
-------------------------------
.. py:function:: paddle.linspace(start, stop, num, dtype
, out=None, device
=None, name=None)
.. py:function:: paddle.linspace(start, stop, num, dtype=None, name=None)
:alias_main: paddle.linspace
:alias: paddle.linspace,paddle.tensor.linspace,paddle.tensor.creation.linspace
...
...
@@ -19,15 +19,18 @@ linspace
- **start** (float|Variable) – start是区间开始的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。
- **stop** (float|Variable) – end是区间结束的变量,可以是一个浮点标量,或是一个shape为[1]的Tensor,该Tensor的数据类型可以是float32或者是float64。
- **num** (int|Variable) – num是给定区间内需要划分的区间数,可以是一个整型标量,或是一个shape为[1]的Tensor,该Tensor的数据类型需为int32。
- **dtype** (string) – 输出Tensor的数据类型,可以是‘float32’或者是‘float64’。
- **out** (Variable,可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。
- **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。
- **dtype** (np.dtype|core.VarDesc.VarType|str,可选) – 输出Tensor的数据类型,可以是‘float32’或者是‘float64’。如果dtype为None,默认类型为float32。
- **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:输出结果的数据类型是float32或float64,表示等间隔划分结果的1-D Tensor,该Tensor的shape大小为 :math:`[num]` ,在mum为1的情况下,仅返回包含start元素值的Tensor。
返回类型:Variable
抛出异常:
- ``TypeError`` - 当start或者stop的数据类型不是float32或者float64。
- ``TypeError`` - 当num的数据类型不是float32或者float64。
- ``TypeError`` - 当dtype的类型不是float32或者float64。
**代码示例**:
.. code-block:: python
...
...
doc/fluid/api_cn/tensor_cn/ones_cn.rst
浏览文件 @
2b4be2e2
...
...
@@ -3,7 +3,7 @@
ones
-------------------------------
.. py:function:: paddle.ones(shape, dtype
, out=None, device
=None)
.. py:function:: paddle.ones(shape, dtype=None)
:alias_main: paddle.ones
:alias: paddle.ones,paddle.tensor.ones,paddle.tensor.creation.ones
...
...
@@ -15,20 +15,34 @@ ones
该OP创建形状为 ``shape`` 、数据类型为 ``dtype`` 且值全为1的Tensor。
参数:
- **shape** (tuple|list) - 输出Tensor的形状。
- **dtype** (np.dtype|core.VarDesc.VarType|str) - 输出Tensor的数据类型,数据类型必须为float16、float32、float64、int32或int64。
- **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。
- **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。
- **shape** (tuple|list|Variable) - 输出Tensor的形状,数据类型为int32或者int64。
- **dtype** (np.dtype|core.VarDesc.VarType|str, 可选) - 输出Tensor的数据类型,数据类型必须为float16、float32、float64、int32或int64。如果dtype为None,默认数据类型为float32。
- **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。
返回:值全为1的Tensor,数据类型和 ``dtype`` 定义的类型一致。
返回类型:Variable
抛出异常:
- ``TypeError`` - 当dtype不是float16、float32、float64、int32或int64中的一个的时候
- ``TypeError`` - 当shape 不是tuple、list、或者Variable的时候。
**代码示例**:
.. code-block:: python
import paddle
data = paddle.ones(shape=[3, 2], dtype='float32') # [[1., 1.], [1., 1.], [1., 1.]]
data = paddle.ones(shape=[2, 2], dtype='float32', device='cpu') # [[1., 1.], [1., 0.]]
paddle.enable_imperative()
data1 = paddle.ones(shape=[3, 2])
# [[1. 1.]
# [1. 1.]
# [1. 1.]]
data2 = paddle.ones(shape=[2, 2], dtype='int32')
# [[1 1]
# [1 1]]
shape = paddle.fill_constant(shape=[2], dtype='int32', value=2)
data3 = paddle.ones(shape=shape, dtype='int32')
# [[1 1]
# [1 1]]
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录