Return the elements, either from x
or y
, depending on the condition
.
Aliases:
tf.compat.v1.where_v2
tf.compat.v2.where
tf.where(
condition,
x=None,
y=None,
name=None
)
Used in the guide:
B
et
te
rp
e
rf
or
ma
nc
ew
i
th
t
f.
fu
nc
ti
on
a
nd
A
ut
oG
ra
ph
Used in the tutorials:
B
et
te
rp
e
rf
or
ma
nc
ew
i
th
t
f.
fu
nc
ti
on
U
ni
co
de
s
tr
in
gs
If bothx
andy
are None, then this operation returns the coordinates of true elements ofcondition
. 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,condition
,x
andy
must be broadcastable to the same shape. Thecondition
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 fromx
(if true) ory
(if false).
Args:
condition
: ATensor
of typebool
x
: ATensor
which is of the same ty
pe asy
, and may
be broadcastable withcondition
andy
.y
: ATensor
which is of the same ty
pe asx
, and may
be broadcastable withcondition
andx
.name
: Aname
of the operation (optional).
Returns:
A Tensor
with the same ty
pe as x
and y
, and shape that is broadcast from condition
, x
, and y
, if x
, y
are non-None. A Tensor
with shape (num_true, dim_size(condition
)).
Raises:
ValueError
: When ex
actly
one ofx
ory
is non-None.