# tf.keras.backend.switch

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/backend/switch) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/keras/backend.py#L4184-L4245) |

Switches between two operations depending on a scalar value.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.keras.backend.switch`](https://www.tensorflow.org/api_docs/python/tf/keras/backend/switch)

<br />

    tf.keras.backend.switch(
        condition, then_expression, else_expression
    )

Note that both `then_expression` and `else_expression`
should be symbolic tensors of the *same shape*.

<br />

<br />

<br />

| ## Arguments ||
|---|---|
| `condition` | tensor (`int` or `bool`). |
| `then_expression` | either a tensor, or a callable that returns a tensor. |
| `else_expression` | either a tensor, or a callable that returns a tensor. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| The selected tensor. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If rank of `condition` is greater than rank of expressions. |

<br />