From 54e491ac4110b937242697846d6933d5b7c5e48e Mon Sep 17 00:00:00 2001 From: danleifeng Date: Sun, 27 Sep 2020 06:31:05 +0000 Subject: [PATCH] fix code example for is_empty; test=develop --- .../api/paddle/fluid/layers/is_empty_cn.rst | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/doc/paddle/api/paddle/fluid/layers/is_empty_cn.rst b/doc/paddle/api/paddle/fluid/layers/is_empty_cn.rst index d0e21720f..c45ac1a1f 100644 --- a/doc/paddle/api/paddle/fluid/layers/is_empty_cn.rst +++ b/doc/paddle/api/paddle/fluid/layers/is_empty_cn.rst @@ -3,7 +3,7 @@ is_empty ------------------------------- -.. py:function:: paddle.fluid.layers.is_empty(x, cond=None) +.. py:function:: paddle.is_empty(x, name=None) @@ -12,24 +12,45 @@ is_empty 参数: - **x** (Variable)-测试的变量 - - **cond** (Variable|None)-可选输出参数,默认为空(None)。若传入了该参数,则该参数中存储返回给定x的测试结果 + - **name** (str,可选)- 输出的名字。默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。 返回:布尔类型的标量。如果变量x为空则值为真 返回类型:Variable -抛出异常:``TypeError``-如果input类型不是Variable或cond存储的返回结果的类型不是bool **代码示例**: .. code-block:: python - import paddle.fluid as fluid - input = fluid.layers.data(name="input", shape=[4, 32, 32], dtype="float32") - res = fluid.layers.is_empty(x=input) - # or: - # fluid.layers.is_empty(x=input, cond=res) + # static mode + import numpy as np + import paddle + paddle.enable_static() + input = paddle.static.data(name="input", shape=[4, 32, 32], dtype="float32") + res = paddle.is_empty(x=input) + exe = paddle.static.Executor(paddle.CPUPlace()) + data = np.ones((4, 32, 32)).astype(np.float32) + out = exe.run(feed={'input':data}, fetch_list=[res]) + print("is_empty: ", out) + # ('out:', [array([False])]) + + +.. code-block:: python + + # dygraph_mode + import paddle + + input = paddle.rand(shape=[4, 32, 32], dtype='float32') + res = paddle.is_empty(x=input) + print("res:", res) + # ('res:', Tensor: eager_tmp_1 + # - place: CPUPlace + # - shape: [1] + # - layout: NCHW + # - dtype: bool + # - data: [0]) -- GitLab