|TensorFlow 1 version||View source on GitHub|
Return the elements where
Compat aliases for migration
See Migration guide for more details.
tf.where( condition, x=None, y=None, name=None )
Used in the notebooks
|Used in the guide||Used in the tutorials|
This operator has two modes: in one mode both
y are provided, in
another mode neither are provided.
condition is always expected to be a
tf.Tensor of type
Retrieving indices of
y are not provided (both are None):
tf.where will return the indices of
condition that are
the form of a 2-D tensor with shape (n, d).
(Where n is the number of matching indices in
and d is the number of dimensions in
Indices are output in row-major order.
tf.where([True, False, False, True])
<tf.Tensor: shape=(2, 1), dtype=int64, numpy=
tf.where([[True, False], [False, True]])
<tf.Tensor: shape=(2, 2), dtype=int64, numpy=
tf.where([[[True, False], [False, True], [True, True]]])
<tf.Tensor: shape=(4, 3), dtype=int64, numpy=
array([[0, 0, 0],
[0, 1, 1],
[0, 2, 0],
[0, 2, 1]])>
y are provided (both have non-None values):
condition tensor acts as a mask that chooses whether the corresponding
element / row in the output should be taken from
(if the element in
condition is True) or
y (if it is false).