# tf.linalg.tensor_diag_part

<br />

|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 2 version](https://www.tensorflow.org/api_docs/python/tf/linalg/tensor_diag_part) |

Returns the diagonal part of the tensor.

#### View aliases


**Main aliases**

\`tf.diag_part\`
**Compat aliases for migration**

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

[`tf.compat.v1.diag_part`](https://www.tensorflow.org/api_docs/python/tf/linalg/tensor_diag_part), [`tf.compat.v1.linalg.tensor_diag_part`](https://www.tensorflow.org/api_docs/python/tf/linalg/tensor_diag_part), \`tf.compat.v2.linalg.tensor_diag_part\`

<br />

    tf.linalg.tensor_diag_part(
        input, name=None
    )

This operation returns a tensor with the `diagonal` part
of the `input`. The `diagonal` part is computed as follows:

Assume `input` has dimensions `[D1,..., Dk, D1,..., Dk]`, then the output is a
tensor of rank `k` with dimensions `[D1,..., Dk]` where:

`diagonal[i1,..., ik] = input[i1, ..., ik, i1,..., ik]`.

#### For example:

    # 'input' is [[1, 0, 0, 0]
                  [0, 2, 0, 0]
                  [0, 0, 3, 0]
                  [0, 0, 0, 4]]

    tf.diag_part(input) ==> [1, 2, 3, 4]

<br />

<br />

<br />

| ## Args ||
|---|---|
| `input` | A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`, `int32`, `int64`, `complex64`, `complex128`. Rank k tensor where k is even and not zero. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor`. Has the same type as `input`. ||

<br />