reduce_any¶
- paddle.fluid.layers.nn. reduce_any ( input, dim=None, keep_dim=False, name=None ) [source]
-
This OP computes the
logical or
of tensor elements over the given dimension, and output the result.- Parameters
-
input (Tensor) – the input tensor, it’s data type should be bool.
dim (list|int|optional) – The dimension along which the logical and is computed. If
None
, compute the logical and over all elements ofinput
and return a Tensor variable with a single element, otherwise must be in the range \([-rank(input), rank(input))\). If \(dim[i] < 0\), the dimension to reduce is \(rank + dim[i]\). The default value is None.keep_dim (bool) – Whether to reserve the reduced dimension in the output Tensor. The result tensor will have one fewer dimension than the
input
unlesskeep_dim
is true. The default value is False.name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
The reduced tensor variable with
logical or
in given dims. - Return type
-
Tensor, the output data type is bool.
Examples
import paddle import paddle.fluid as fluid import paddle.fluid.layers as layers import numpy as np # x is a bool Tensor variable with following elements: # [[True, False] # [False, False]] x = fluid.layers.assign(np.array([[1, 0], [0, 0]], dtype='int32')) x = fluid.layers.cast(x, 'bool') out = fluid.layers.reduce_any(x) # True out = fluid.layers.reduce_any(x, dim=0) # [True, False] out = fluid.layers.reduce_any(x, dim=-1) # [True, False] # keep_dim=False, x.shape=(2,2), out.shape=(2,) out = fluid.layers.reduce_any(x, dim=1, keep_dim=True) # [[True], [False]] # keep_dim=True, x.shape=(2,2), out.shape=(2,1)