- paddle. any ( x, axis=None, keepdim=False, name=None )
Computes the the
logical orof tensor elements over the given dimension.
x (Tensor) – An N-D Tensor, the input data type should be bool.
axis (int|list|tuple, optional) – The dimensions along which the
logical oris compute. If
None, and all elements of
xand 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
keepdimis true, default value is False.
name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name
logical oron the specified axis of input Tensor x, it’s data type is bool.
- Return type
ValueError – If the data type of x is not bool.
TypeError – The type of
axismust be int, list or tuple.
import paddle import numpy as np # x is a bool Tensor with following elements: # [[True, False] # [False, False]] x = paddle.assign(np.array([[1, 0], [1, 1]], dtype='int32')) print(x) x = paddle.cast(x, 'bool') # 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) # keep_dim=False, out3 should be [True, True], out.shape should be (2,) out3 = paddle.any(x, axis=-1) # [True, True] print(out3) # keep_dim=True, result should be [[True], [True]], out.shape should be (2,1) out4 = paddle.any(x, axis=1, keepdim=True) out4 = paddle.cast(out4, 'int32') # [[True], [True]] print(out4)