# tensorflow::ops::MatrixDiagPartV2 Class Reference

# tensorflow::
ops::
MatrixDiagPartV2

`
#include <array_ops.h>
`


Returns the batched diagonal part of a batched tensor.

## Summary


Returns a tensor with the
`
k[0]
`
-th to
`
k[1]
`
-th diagonals of the batched
`
input
`
.


Assume
`
input
`
has
`
r
`
dimensions
`
[I, J, ..., L, M, N]
`
. Let
`
max_diag_len
`
be the maximum length among all diagonals to be extracted,
`
max_diag_len = min(M + min(k[1], 0), N + min(-k[0], 0))
`
Let
`
num_diags
`
be the number of diagonals to extract,
`
num_diags = k[1] - k[0] + 1
`
.


If
`
num_diags == 1
`
, the output tensor is of rank
`
r - 1
`
with shape
`
[I, J, ..., L, max_diag_len]
`
and values:


```
diagonal[i, j, ..., l, n]
  = input[i, j, ..., l, n+y, n+x] ; if 0 <= n+y < M and 0 <= n+x < N,
    padding_value                 ; otherwise.
```
where `
y = max(-k[1], 0)
` , `
x = max(k[1], 0)
` .

<br />


Otherwise, the output tensor has rank
`
r
`
with dimensions
`
[I, J, ..., L, num_diags, max_diag_len]
`
with values:


```
diagonal[i, j, ..., l, m, n]
  = input[i, j, ..., l, n+y, n+x] ; if 0 <= n+y < M and 0 <= n+x < N,
    padding_value                 ; otherwise.
```
where `
d = k[1] - m
` , `
y = max(-d, 0)
` , and `
x = max(d, 0)
` .

<br />


The input must be at least a matrix.


For example:


```
input = np.array([[[1, 2, 3, 4],  # Input shape: (2, 3, 4)
                   [5, 6, 7, 8],
                   [9, 8, 7, 6]],
                  [[5, 4, 3, 2],
                   [1, 2, 3, 4],
                   [5, 6, 7, 8]]])
```

<br />


```
# A main diagonal from each batch.
tf.matrix_diag_part(input) ==> [[1, 6, 7],  # Output shape: (2, 3)
                                [5, 2, 7]]
```

<br />


```
# A superdiagonal from each batch.
tf.matrix_diag_part(input, k = 1)
  ==> [[2, 7, 6],  # Output shape: (2, 3)
       [4, 3, 8]]
```

<br />


```
# A tridiagonal band from each batch.
tf.matrix_diag_part(input, k = (-1, 1))
  ==> [[[2, 7, 6],  # Output shape: (2, 3, 3)
        [1, 6, 7],
        [5, 8, 0]],
       [[4, 3, 8],
        [5, 2, 7],
        [1, 6, 0]]]
```

<br />


```
# Padding value = 9
tf.matrix_diag_part(input, k = (1, 3), padding_value = 9)
  ==> [[[4, 9, 9],  # Output shape: (2, 3, 3)
        [3, 8, 9],
        [2, 7, 6]],
       [[2, 9, 9],
        [3, 4, 9],
        [4, 3, 8]]]
```

<br />


Args:

- scope: A [Scope](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object
- input: Rank `
  r
  ` tensor where `
  r >= 2
  ` .
- k: Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main diagonal, and negative value means subdiagonals. `
  k
  ` can be a single integer (for a single diagonal) or a pair of integers specifying the low and high ends of a matrix band. `
  k[0]
  ` must not be larger than `
  k[1]
  ` .
- padding_value: The value to fill the area outside the specified diagonal band with. Default is 0.

<br />


Returns:

- `
  https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output
  ` : The extracted diagonal(s).

<br />

| ### Constructors and Destructors ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/matrix-diag-part-v2#classtensorflow_1_1ops_1_1_matrix_diag_part_v2_1ad3de7ab4ab1196ff0eb0a0b9712563ef (const :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input input, :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input k, :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input padding_value) ` ||

| ### Public attributes ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/matrix-diag-part-v2#classtensorflow_1_1ops_1_1_matrix_diag_part_v2_1a7a8892ae88249cf5f89b97544d71a59c ` | ` :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output ` |
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/matrix-diag-part-v2#classtensorflow_1_1ops_1_1_matrix_diag_part_v2_1aefc836bb535eab5db669667a152eba42 ` | ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation ` |

| ### Public functions ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/matrix-diag-part-v2#classtensorflow_1_1ops_1_1_matrix_diag_part_v2_1a0b20ceb05713921670ce29cf7671a152 () const ` | ` ::tensorflow::Node * ` |
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/matrix-diag-part-v2#classtensorflow_1_1ops_1_1_matrix_diag_part_v2_1acb91e8a485455813fcd8d9d3558c793b () const ` | ` ` |
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/matrix-diag-part-v2#classtensorflow_1_1ops_1_1_matrix_diag_part_v2_1a18e6d0e922c930c2880112f18f2ac011 () const ` | ` ` |

## Public attributes

### diagonal

```
::tensorflow::Output diagonal
```

### operation

```
Operation operation
```

## Public functions

### MatrixDiagPartV2

```
 MatrixDiagPartV2(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input input,
  ::tensorflow::Input k,
  ::tensorflow::Input padding_value
)
```

### node

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

### operator::tensorflow::Input

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

### operator::tensorflow::Output

```
 operator::tensorflow::Output() const 
```