any¶
- paddle. any ( x, axis=None, keepdim=False, name=None ) [source]
-
Computes the
logical or
of tensor elements over the given dimension, and return the result.- Parameters
-
x (Tensor) – An N-D Tensor, the input data type should be bool.
axis (int|list|tuple, optional) – The dimensions along which the
logical or
is compute. IfNone
, and all elements ofx
and return a Tensor with a single element, otherwise must be in the range \([-rank(x), rank(x))\). If \(axis[i] < 0\), the dimension to reduce is \(rank + axis[i]\).keepdim (bool, optional) – Whether to reserve the reduced dimension in the output Tensor. The result Tensor will have one fewer dimension than the
x
unlesskeepdim
is true, default value is False.name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
Results the
logical or
on the specified axis of input Tensor x, it’s data type is bool. - Return type
-
Tensor
Examples
import paddle x = paddle.to_tensor([[1, 0], [1, 1]], dtype='int32') x = paddle.assign(x) print(x) x = paddle.cast(x, 'bool') # x is a bool Tensor with following elements: # [[True, False] # [True, True]] # out1 should be True out1 = paddle.any(x) # True print(out1) # out2 should be [True, True] out2 = paddle.any(x, axis=0) # [True, True] print(out2) # keepdim=False, out3 should be [True, True], out.shape should be (2,) out3 = paddle.any(x, axis=-1) # [True, True] print(out3) # keepdim=True, result should be [[True], [True]], out.shape should be (2,1) out4 = paddle.any(x, axis=1, keepdim=True) # [[True], [True]] print(out4)