tf.raw_ops.Select
Selects elements from x
or y
, depending on condition
.
tf.raw_ops.Select( condition, x, y, name=None )
The x
, and y
tensors must all have the same shape, and the output will also have that shape.
The condition
tensor must be a scalar if x
and y
are scalars. If x
and y
are vectors or higher rank, then condition
must be either a scalar, 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
.
For example:
# 'condition' tensor is [[True, False] # [False, True]] # 't' is [[1, 2], # [3, 4]] # 'e' is [[5, 6], # [7, 8]] select(condition, t, e) # => [[1, 6], [7, 4]] # 'condition' tensor is [True, False] # 't' is [[1, 2], # [3, 4]] # 'e' is [[5, 6], # [7, 8]] select(condition, t, e) ==> [[1, 2], [7, 8]]
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 type and shape as x . |
name | A name for the operation (optional). |
Returns | |
---|---|
A Tensor . Has the same type as t . |
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.4/api_docs/python/tf/raw_ops/Select