tf.compat.v1.where
Stay organized with collections
Save and categorize content based on your preferences.
Return the elements, either from x
or y
, depending on the condition
.
tf.compat.v1.where(
condition, x=None, y=None, name=None
)
If both x
and y
are None, then this operation returns the coordinates of
true elements of 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 input. Indices are output in row-major
order.
If both non-None, x
and y
must have the same shape.
The condition
tensor must be a scalar if x
and y
are scalar.
If x
and y
are tensors of higher rank, then condition
must be either a
vector with size matching the first dimension of x
, or must have the same
shape as x
.
The condition
tensor acts as a mask that chooses, based on the value at each
element, whether the corresponding element / row in the output should be taken
from x
(if true) or y
(if false).
If condition
is a vector and x
and y
are higher rank matrices, then it
chooses which row (outer dimension) to copy from x
and y
. If condition
has the same shape as x
and y
, then it chooses which element to copy from
x
and y
.
Args |
condition
|
A Tensor of type bool
|
x
|
A Tensor which may have the same shape as condition . If condition is
rank 1, x may have higher rank, but its first dimension must match the
size of condition .
|
y
|
A tensor with the same shape and type as x .
|
name
|
A name of the operation (optional)
|
Returns |
A Tensor with the same type and shape as x , y if they are non-None.
Otherwise, a Tensor with shape (num_true, rank(condition)) .
|
Raises |
ValueError
|
When exactly one of x or y is non-None.
|
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.
Last updated 2020-10-01 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 2020-10-01 UTC."],[],[],null,["# tf.compat.v1.where\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/ops/array_ops.py#L3704-L3755) |\n\nReturn the elements, either from `x` or `y`, depending on the `condition`. \n\n tf.compat.v1.where(\n condition, x=None, y=None, name=None\n )\n\nIf both `x` and `y` are None, then this operation returns the coordinates of\ntrue elements of `condition`. The coordinates are returned in a 2-D tensor\nwhere the first dimension (rows) represents the number of true elements, and\nthe second dimension (columns) represents the coordinates of the true\nelements. Keep in mind, the shape of the output tensor can vary depending on\nhow many true values there are in input. Indices are output in row-major\norder.\n\nIf both non-None, `x` and `y` must have the same shape.\nThe `condition` tensor must be a scalar if `x` and `y` are scalar.\nIf `x` and `y` are tensors of higher rank, then `condition` must be either a\nvector with size matching the first dimension of `x`, or must have the same\nshape as `x`.\n\nThe `condition` tensor acts as a mask that chooses, based on the value at each\nelement, whether the corresponding element / row in the output should be taken\nfrom `x` (if true) or `y` (if false).\n\nIf `condition` is a vector and `x` and `y` are higher rank matrices, then it\nchooses which row (outer dimension) to copy from `x` and `y`. If `condition`\nhas the same shape as `x` and `y`, then it chooses which element to copy from\n`x` and `y`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `condition` | A `Tensor` of type `bool` |\n| `x` | A Tensor which may have the same shape as `condition`. If `condition` is rank 1, `x` may have higher rank, but its first dimension must match the size of `condition`. |\n| `y` | A `tensor` with the same shape and type as `x`. |\n| `name` | A name of 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` with the same type and shape as `x`, `y` if they are non-None. Otherwise, a `Tensor` with shape `(num_true, rank(condition))`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|---------------------------------------------|\n| `ValueError` | When exactly one of `x` or `y` is non-None. |\n\n\u003cbr /\u003e"]]