未验证 提交 232c4e3b 编写于 作者: C cnn 提交者: GitHub

fix sample code of reduce_all and reduce_any, test=document_fix (#28237)

上级 344c5213
...@@ -4717,15 +4717,15 @@ def reduce_all(input, dim=None, keep_dim=False, name=None): ...@@ -4717,15 +4717,15 @@ def reduce_all(input, dim=None, keep_dim=False, name=None):
# x is a bool Tensor variable with following elements: # x is a bool Tensor variable with following elements:
# [[True, False] # [[True, False]
# [True, True]] # [True, True]]
x = paddle.assign(np.array([[1, 0], [1, 1]], dtype='int32')) x = fluid.layers.assign(np.array([[1, 0], [1, 1]], dtype='int32'))
x = paddle.cast(x, 'bool') x = fluid.layers.cast(x, 'bool')
out = paddle.reduce_all(x) # False out = fluid.layers.reduce_all(x) # False
out = paddle.reduce_all(x, dim=0) # [True, False] out = fluid.layers.reduce_all(x, dim=0) # [True, False]
out = paddle.reduce_all(x, dim=-1) # [False, True] out = fluid.layers.reduce_all(x, dim=-1) # [False, True]
# keep_dim=False, x.shape=(2,2), out.shape=(2,) # keep_dim=False, x.shape=(2,2), out.shape=(2,)
out = paddle.reduce_all(x, dim=1, keep_dim=True) # [[False], [True]] out = fluid.layers.reduce_all(x, dim=1, keep_dim=True) # [[False], [True]]
# keep_dim=True, x.shape=(2,2), out.shape=(2,1) # keep_dim=True, x.shape=(2,2), out.shape=(2,1)
""" """
...@@ -4777,15 +4777,15 @@ def reduce_any(input, dim=None, keep_dim=False, name=None): ...@@ -4777,15 +4777,15 @@ def reduce_any(input, dim=None, keep_dim=False, name=None):
# x is a bool Tensor variable with following elements: # x is a bool Tensor variable with following elements:
# [[True, False] # [[True, False]
# [False, False]] # [False, False]]
x = paddle.assign(np.array([[1, 0], [0, 0]], dtype='int32')) x = fluid.layers.assign(np.array([[1, 0], [0, 0]], dtype='int32'))
x = paddle.cast(x, 'bool') x = fluid.layers.cast(x, 'bool')
out = paddle.reduce_any(x) # True out = fluid.layers.reduce_any(x) # True
out = paddle.reduce_any(x, dim=0) # [True, False] out = fluid.layers.reduce_any(x, dim=0) # [True, False]
out = paddle.reduce_any(x, dim=-1) # [True, False] out = fluid.layers.reduce_any(x, dim=-1) # [True, False]
# keep_dim=False, x.shape=(2,2), out.shape=(2,) # keep_dim=False, x.shape=(2,2), out.shape=(2,)
out = paddle.reduce_any(x, dim=1, out = fluid.layers.reduce_any(x, dim=1,
keep_dim=True) # [[True], [False]] keep_dim=True) # [[True], [False]]
# keep_dim=True, x.shape=(2,2), out.shape=(2,1) # keep_dim=True, x.shape=(2,2), out.shape=(2,1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册