# tf.compat.v1.to_int32

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/ops/math_ops.py#L1182-L1219) |

Casts a tensor to type `int32`. (deprecated)

    tf.compat.v1.to_int32(
        x, name='ToInt32'
    )

<br />

## Migrate to TF2

<br />

> [!CAUTION]
> **Caution:** This API was designed for TensorFlow v1. Continue reading for details on how to migrate from this API to a native TensorFlow v2 equivalent. See the [TensorFlow v1 to TensorFlow v2 migration guide](https://www.tensorflow.org/guide/migrate) for instructions on how to migrate the rest of your code.

This name was deprecated and removed in TF2, but has an exact replacement
[`tf.cast(..., tf.int32)`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/cast). There are no further issues with eager execution or
tf.function.

Before:

    tf.compat.v1.to_int32(tf.constant(1, dtype=tf.int64))
    <tf.Tensor: shape=(), dtype=int32, numpy=1>

After:

    tf.cast(tf.constant(1, dtype=tf.int64), tf.int32)
    <tf.Tensor: shape=(), dtype=int32, numpy=1>

<br />

<br />

## Description

> [!WARNING]
> **Deprecated:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use [`tf.cast`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/cast) instead.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `x` | A `Tensor` or `SparseTensor` or `IndexedSlices`. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor` or `SparseTensor` or `IndexedSlices` with same shape as `x` with type `int32`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If `x` cannot be cast to the `int32`. |

<br />