reduce_all¶
- paddle.fluid.layers.nn. reduce_all ( input, dim=None, keep_dim=False, name=None ) [source]
- 
         This OP computes the logical andof 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 of- inputand 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 - inputunless- keep_dimis true. The default value is False.
- name (str|None) – A name for this layer(optional). If set None, the layer will be named automatically. The default value is None. 
 
- Returns
- 
           The reduced tensor variable with logical andin 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] # [True, True]] x = fluid.layers.assign(np.array([[1, 0], [1, 1]], dtype='int32')) x = fluid.layers.cast(x, 'bool') out = fluid.layers.reduce_all(x) # False out = fluid.layers.reduce_all(x, dim=0) # [True, False] out = fluid.layers.reduce_all(x, dim=-1) # [False, True] # keep_dim=False, x.shape=(2,2), out.shape=(2,) out = fluid.layers.reduce_all(x, dim=1, keep_dim=True) # [[False], [True]] # keep_dim=True, x.shape=(2,2), out.shape=(2,1) 
