tf.raw_ops.Where
bookmark_borderbookmark
Stay organized with collections
Save and categorize content based on your preferences.
Returns locations of nonzero / true values in a tensor.
View aliases
Compat aliases for migration
See
Migration guide for
more details.
tf.compat.v1.raw_ops.Where
tf.raw_ops.Where(
condition, name=None
)
This operation returns the coordinates of true elements in condition
. The
coordinates are returned in a 2-D tensor where the first dimension (rows)
represents the number of true elements, and the second dimension (columns)
represents the coordinates of the true elements. Keep in mind, the shape of
the output tensor can vary depending on how many true values there are in
condition
. Indices are output in row-major order.
For example:
# 'input' tensor is [[True, False]
# [True, False]]
# 'input' has two true values, so output has two coordinates.
# 'input' has rank of 2, so coordinates have two indices.
where(input) ==> [[0, 0],
[1, 0]]
# `condition` tensor is [[[True, False]
# [True, False]]
# [[False, True]
# [False, True]]
# [[False, False]
# [False, True]]]
# 'input' has 5 true values, so output has 5 coordinates.
# 'input' has rank of 3, so coordinates have three indices.
where(input) ==> [[0, 0, 0],
[0, 1, 0],
[1, 0, 1],
[1, 1, 1],
[2, 1, 1]]
# `condition` tensor is [[[1.5, 0.0]
# [-0.5, 0.0]]
# [[0.0, 0.25]
# [0.0, 0.75]]
# [[0.0, 0.0]
# [0.0, 0.01]]]
# 'input' has 5 nonzero values, so output has 5 coordinates.
# 'input' has rank of 3, so coordinates have three indices.
where(input) ==> [[0, 0, 0],
[0, 1, 0],
[1, 0, 1],
[1, 1, 1],
[2, 1, 1]]
# `condition` tensor is [[[1.5 + 0.0j, 0.0 + 0.0j]
# [0.0 + 0.5j, 0.0 + 0.0j]]
# [[0.0 + 0.0j, 0.25 + 1.5j]
# [0.0 + 0.0j, 0.75 + 0.0j]]
# [[0.0 + 0.0j, 0.0 + 0.0j]
# [0.0 + 0.0j, 0.01 + 0.0j]]]
# 'input' has 5 nonzero magnitude values, so output has 5 coordinates.
# 'input' has rank of 3, so coordinates have three indices.
where(input) ==> [[0, 0, 0],
[0, 1, 0],
[1, 0, 1],
[1, 1, 1],
[2, 1, 1]]
Args |
condition
|
A Tensor . Must be one of the following types: float32 , float64 , int32 , uint8 , int16 , int8 , complex64 , int64 , qint8 , quint8 , qint32 , bfloat16 , qint16 , quint16 , uint16 , complex128 , half , uint32 , uint64 , bool .
|
name
|
A name for the operation (optional).
|
Returns |
A Tensor of type int64 .
|
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-04-26 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-04-26 UTC."],[],[],null,["# tf.raw_ops.Where\n\n\u003cbr /\u003e\n\nReturns locations of nonzero / true values in a tensor.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.raw_ops.Where`](https://www.tensorflow.org/api_docs/python/tf/raw_ops/Where)\n\n\u003cbr /\u003e\n\n tf.raw_ops.Where(\n condition, name=None\n )\n\nThis operation returns the coordinates of true elements in `condition`. The\ncoordinates are returned in a 2-D tensor where the first dimension (rows)\nrepresents the number of true elements, and the second dimension (columns)\nrepresents the coordinates of the true elements. Keep in mind, the shape of\nthe output tensor can vary depending on how many true values there are in\n`condition`. Indices are output in row-major order.\n\n#### For example:\n\n # 'input' tensor is [[True, False]\n # [True, False]]\n # 'input' has two true values, so output has two coordinates.\n # 'input' has rank of 2, so coordinates have two indices.\n where(input) ==\u003e [[0, 0],\n [1, 0]]\n\n # `condition` tensor is [[[True, False]\n # [True, False]]\n # [[False, True]\n # [False, True]]\n # [[False, False]\n # [False, True]]]\n # 'input' has 5 true values, so output has 5 coordinates.\n # 'input' has rank of 3, so coordinates have three indices.\n where(input) ==\u003e [[0, 0, 0],\n [0, 1, 0],\n [1, 0, 1],\n [1, 1, 1],\n [2, 1, 1]]\n\n # `condition` tensor is [[[1.5, 0.0]\n # [-0.5, 0.0]]\n # [[0.0, 0.25]\n # [0.0, 0.75]]\n # [[0.0, 0.0]\n # [0.0, 0.01]]]\n # 'input' has 5 nonzero values, so output has 5 coordinates.\n # 'input' has rank of 3, so coordinates have three indices.\n where(input) ==\u003e [[0, 0, 0],\n [0, 1, 0],\n [1, 0, 1],\n [1, 1, 1],\n [2, 1, 1]]\n\n # `condition` tensor is [[[1.5 + 0.0j, 0.0 + 0.0j]\n # [0.0 + 0.5j, 0.0 + 0.0j]]\n # [[0.0 + 0.0j, 0.25 + 1.5j]\n # [0.0 + 0.0j, 0.75 + 0.0j]]\n # [[0.0 + 0.0j, 0.0 + 0.0j]\n # [0.0 + 0.0j, 0.01 + 0.0j]]]\n # 'input' has 5 nonzero magnitude values, so output has 5 coordinates.\n # 'input' has rank of 3, so coordinates have three indices.\n where(input) ==\u003e [[0, 0, 0],\n [0, 1, 0],\n [1, 0, 1],\n [1, 1, 1],\n [2, 1, 1]]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `condition` | A `Tensor`. Must be one of the following types: `float32`, `float64`, `int32`, `uint8`, `int16`, `int8`, `complex64`, `int64`, `qint8`, `quint8`, `qint32`, `bfloat16`, `qint16`, `quint16`, `uint16`, `complex128`, `half`, `uint32`, `uint64`, `bool`. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor` of type `int64`. ||\n\n\u003cbr /\u003e"]]