tf.where

Return the elements where condition is True (multiplexing x and y).

Used in the notebooks

Used in the guide Used in the tutorials

This operator has two modes: in one mode both x and y are provided, in another mode neither are provided. condition is always expected to be a tf.Tensor of type bool.

Retrieving indices of True elements

If x and y are not provided (both are None):

tf.where will return the indices of condition that are True, in the form of a 2-D tensor with shape (n, d). (Where n is the number of matching indices in condition, and d is the number of dimensions in condition).

Indices are output in row-major order.

tf.where([True, False, False, True])
<tf.Tensor: shape=(2, 1), dtype=int64, numpy=
array([[0],
       [3]])>