# tf.raw_ops.MatrixDiagPart

<br />

Returns the batched diagonal part of a batched tensor.

#### View aliases


**Compat aliases for migration**

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

[`tf.compat.v1.raw_ops.MatrixDiagPart`](https://www.tensorflow.org/api_docs/python/tf/raw_ops/MatrixDiagPart)

<br />

    tf.raw_ops.MatrixDiagPart(
        input, name=None
    )

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

Assume `input` has `k` dimensions `[I, J, K, ..., M, N]`, then the output is a
tensor of rank `k - 1` with dimensions `[I, J, K, ..., min(M, N)]` where:

`diagonal[i, j, k, ..., n] = input[i, j, k, ..., n, n]`.

The input must be at least a matrix.

#### For example:

    # 'input' is [[[1, 0, 0, 0]
                   [0, 2, 0, 0]
                   [0, 0, 3, 0]
                   [0, 0, 0, 4]],
                  [[5, 0, 0, 0]
                   [0, 6, 0, 0]
                   [0, 0, 7, 0]
                   [0, 0, 0, 8]]]

    and input.shape = (2, 4, 4)

    tf.matrix_diag_part(input) ==> [[1, 2, 3, 4], [5, 6, 7, 8]]

    which has shape (2, 4)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `input` | A `Tensor`. Rank `k` tensor where `k >= 2`. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

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

<br />