Return the elements, either from x or y, depending on the condition.
Aliases:
tf.compat.v1.where_v2tf.compat.v2.where
tf.where(
condition,
x=None,
y=None,
name=None
)
Used in the guide:
Betterperformancewithtf.functionandAutoGraph
Used in the tutorials:
Betterperformancewithtf.functionUnicodestringsIf bothxandyare 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 varydepending on how manytrue values there are in input. Indices are output in row-major order. If both non-None,condition,xandymust be broadcastable to the same shape. Theconditiontensor 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: ATensorof typeboolx: ATensorwhich is of the same type asy, and maybe broadcastable withconditionandy.y: ATensorwhich is of the same type asx, and maybe broadcastable withconditionandx.name: Anameof the operation (optional).
Returns:
A Tensor with the same type 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 exactlyone ofxoryis non-None.