<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/core.py#L863-L882) |

Cast a tensor to the desired dtype.

    tf.keras.ops.cast(
        x, dtype
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `x` | A tensor or variable. |
| `dtype` | The target type. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A tensor of the specified `dtype`. ||

<br />

#### Example:

    x = keras.ops.arange(4)
    x = keras.ops.cast(x, dtype="float16")