Return the elements, either from `x` or `y`, depending on the `condition`. : If both `x` and `y` are `None`: Returns the coordinates of true elements of `condition`. The coordinates are returned in a 2-D tensor with shape `[num_true_values, dim_size(condition)]`, where `result[i]` is
(condition, x=None, y=None, name=None)
| 28 | |
| 29 | |
| 30 | def where(condition, x=None, y=None, name=None): |
| 31 | """Return the elements, either from `x` or `y`, depending on the `condition`. |
| 32 | |
| 33 | : If both `x` and `y` are `None`: |
| 34 | Returns the coordinates of true elements of `condition`. The coordinates |
| 35 | are returned in a 2-D tensor with shape |
| 36 | `[num_true_values, dim_size(condition)]`, where `result[i]` is the |
| 37 | coordinates of the `i`th true value (in row-major order). |
| 38 | |
| 39 | : If both `x` and `y` are non-`None`: |
| 40 | Returns a tensor formed by selecting values from `x` where condition is |
| 41 | true, and from `y` when condition is false. In particular: |
| 42 | |
| 43 | : If `condition`, `x`, and `y` all have the same shape: |
| 44 | |
| 45 | * `result[i1...iN] = x[i1...iN]` if `condition[i1...iN]` is true. |
| 46 | * `result[i1...iN] = y[i1...iN]` if `condition[i1...iN]` is false. |
| 47 | |
| 48 | : Otherwise: |
| 49 | |
| 50 | * `condition` must be a vector. |
| 51 | * `x` and `y` must have the same number of dimensions. |
| 52 | * The outermost dimensions of `condition`, `x`, and `y` must all have the |
| 53 | same size. |
| 54 | * `result[i] = x[i]` if `condition[i]` is true. |
| 55 | * `result[i] = y[i]` if `condition[i]` is false. |
| 56 | |
| 57 | Args: |
| 58 | condition: A potentially ragged tensor of type `bool` |
| 59 | x: A potentially ragged tensor (optional). |
| 60 | y: A potentially ragged tensor (optional). Must be specified if `x` is |
| 61 | specified. Must have the same rank and type as `x`. |
| 62 | name: A name of the operation (optional) |
| 63 | |
| 64 | Returns: |
| 65 | : If both `x` and `y` are `None`: |
| 66 | A `Tensor` with shape `(num_true, dim_size(condition))`. |
| 67 | : Otherwise: |
| 68 | A potentially ragged tensor with the same type, rank, and outermost |
| 69 | dimension size as `x` and `y`. |
| 70 | `result.ragged_rank = max(x.ragged_rank, y.ragged_rank)`. |
| 71 | |
| 72 | Raises: |
| 73 | ValueError: When exactly one of `x` or `y` is non-`None`; or when |
| 74 | `condition`, `x`, and `y` have incompatible shapes. |
| 75 | |
| 76 | #### Examples: |
| 77 | ```python |
| 78 | >>> # Coordinates where condition is true. |
| 79 | >>> condition = tf.compat.v1.ragged.constant_value( |
| 80 | ... [[True, False, True], [False, True]]) |
| 81 | >>> ragged.where(condition) |
| 82 | [[0, 0], [0, 2], [1, 1]] |
| 83 | |
| 84 | >>> # Elementwise selection between x and y, based on condition. |
| 85 | >>> condition = tf.compat.v1.ragged.constant_value( |
| 86 | ... [[True, False, True], [False, True]]) |
| 87 | >>> x = tf.compat.v1.ragged.constant_value([['A', 'B', 'C'], ['D', 'E']]) |
nothing calls this directly
no test coverage detected