提交 54e491ac 编写于 作者: D danleifeng

fix code example for is_empty; test=develop

上级 f457a8bf
......@@ -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])
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册