tf.keras.ops.any | TensorFlow v2.16.1 (original) (raw)
Test whether any array element along a given axis evaluates to True.
View aliases
Main aliases
tf.keras.ops.any(
x, axis=None, keepdims=False
)
| Args | |
|---|---|
| x | Input tensor. |
| axis | An integer or tuple of integers that represent the axis along which a logical OR reduction is performed. The default (axis=None) is to perform a logical OR over all the dimensions of the input array. axis may be negative, in which case it counts for the last to the first axis. |
| keepdims | If True, axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. Defaults to False. |
| Returns |
|---|
| The tensor containing the logical OR reduction over the axis. |
Examples:
x = keras.ops.convert_to_tensor([True, False])
keras.ops.any(x)
array(True, shape=(), dtype=bool)
x = keras.ops.convert_to_tensor([[True, False], [True, True]])
keras.ops.any(x, axis=0)
array([ True True], shape=(2,), dtype=bool)
keepdims=True outputs a tensor with dimensions reduced to one.
>>> x = keras.ops.convert_to_tensor([[True, False], [True, True]])
>>> keras.ops.all(x, keepdims=True)
array([[False]], shape=(1, 1), dtype=bool)