Have a question? Connect with the community at the TensorFlow Forum

# tensorflow::ops::MatrixDiagPart

`#include <array_ops.h>`

Returns the batched diagonal part of a batched tensor.

## Summary

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)
```

Arguments:

• scope: A Scope object
• input: Rank `k` tensor where `k >= 2`.

Returns:

• `Output`: The extracted diagonal(s) having shape `diagonal.shape = input.shape[:-2] + [min(input.shape[-2:])]`.

### Constructors and Destructors

`MatrixDiagPart(const ::tensorflow::Scope & scope, ::tensorflow::Input input)`

### Public attributes

`diagonal`
`::tensorflow::Output`
`operation`
`Operation`

### Public functions

`node() const `
`::tensorflow::Node *`
`operator::tensorflow::Input() const `
``` ```
``` ```
`operator::tensorflow::Output() const `
``` ```
``` ```

## Public attributes

### diagonal

`::tensorflow::Output diagonal`

### operation

`Operation operation`

## Public functions

### MatrixDiagPart

``` MatrixDiagPart(
const ::tensorflow::Scope & scope,
::tensorflow::Input input
)```

### node

`::tensorflow::Node * node() const `

### operator::tensorflow::Input

` operator::tensorflow::Input() const `

### operator::tensorflow::Output

` operator::tensorflow::Output() const `
[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]