paddle.fluid.layers.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.

  • input (Variable) – The input variable which is a Tensor or LoDTensor, the input 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 of input 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 unless keep_dim is true. The default value is False.

  • name (str|None) – A name for this layer(optional). If set None, the layer


The reduced tensor variable with logical or in given dims.

Return type

Variable, the output data type is bool.


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 = layers.assign(np.array([[1, 0], [0, 0]], dtype='int32'))
x = layers.cast(x, 'bool')

out = layers.reduce_any(x)  # True
out = layers.reduce_any(x, dim=0)  # [True, False]
out = layers.reduce_any(x, dim=-1)  # [True, False]
# keep_dim=False, x.shape=(2,2), out.shape=(2,)

out = layers.reduce_any(x, dim=1,
                         keep_dim=True)  # [[True], [False]]
# keep_dim=True, x.shape=(2,2), out.shape=(2,1)