# tf.eye

<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/linalg_ops.py#L192-L237) |

Construct an identity matrix, or a batch of matrices.

#### View aliases


**Main aliases**

[`tf.linalg.eye`](https://www.tensorflow.org/api_docs/python/tf/eye)
**Compat aliases for migration**

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

[`tf.compat.v1.eye`](https://www.tensorflow.org/api_docs/python/tf/eye), [`tf.compat.v1.linalg.eye`](https://www.tensorflow.org/api_docs/python/tf/eye)

<br />

    tf.eye(
        num_rows,
        num_columns=None,
        batch_shape=None,
        dtype=https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/dtypes#float32,
        name=None
    )

See also [`tf.ones`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/ones), [`tf.zeros`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/zeros), [`tf.fill`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/fill), [`tf.one_hot`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/one_hot).

    # Construct one identity matrix.
    tf.eye(2)
    ==> [[1., 0.],
         [0., 1.]]

    # Construct a batch of 3 identity matrices, each 2 x 2.
    # batch_identity[i, :, :] is a 2 x 2 identity matrix, i = 0, 1, 2.
    batch_identity = tf.eye(2, batch_shape=[3])

    # Construct one 2 x 3 "identity" matrix
    tf.eye(2, num_columns=3)
    ==> [[ 1.,  0.,  0.],
         [ 0.,  1.,  0.]]

<br />

<br />

<br />

| ## Args ||
|---|---|
| `num_rows` | Non-negative `int32` scalar `Tensor` giving the number of rows in each batch matrix. |
| `num_columns` | Optional non-negative `int32` scalar `Tensor` giving the number of columns in each batch matrix. Defaults to `num_rows`. |
| `batch_shape` | A list or tuple of Python integers or a 1-D `int32` `Tensor`. If provided, the returned `Tensor` will have leading batch dimensions of this shape. |
| `dtype` | The type of an element in the resulting `Tensor` |
| `name` | A name for this `Op`. Defaults to "eye". |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor` of shape `batch_shape + [num_rows, num_columns]` ||

<br />