tf.keras.ops.any
Stay organized with collections
Save and categorize content based on your preferences.
Test whether any array element along a given axis evaluates to True
.
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)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.ops.any\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/numpy.py#L262-L296) |\n\nTest whether any array element along a given axis evaluates to `True`.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.keras.ops.numpy.any`](https://www.tensorflow.org/api_docs/python/tf/keras/ops/any)\n\n\u003cbr /\u003e\n\n tf.keras.ops.any(\n x, axis=None, keepdims=False\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `x` | Input tensor. |\n| `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. |\n| `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`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| The tensor containing the logical OR reduction over the `axis`. ||\n\n\u003cbr /\u003e\n\n#### Examples:\n\n x = keras.ops.convert_to_tensor([True, False])\n keras.ops.any(x)\n array(True, shape=(), dtype=bool)\n\n x = keras.ops.convert_to_tensor([[True, False], [True, True]])\n keras.ops.any(x, axis=0)\n array([ True True], shape=(2,), dtype=bool)\n\n`keepdims=True` outputs a tensor with dimensions reduced to one. \n\n \u003e\u003e\u003e x = keras.ops.convert_to_tensor([[True, False], [True, True]])\n \u003e\u003e\u003e keras.ops.all(x, keepdims=True)\n array([[False]], shape=(1, 1), dtype=bool)"]]