diagonal

diagonal(x: array, /, *, offset: int = 0) array

Returns the specified diagonals of a matrix (or a stack of matrices) x.

Parameters
  • x (array) – input array having shape (..., M, N) and whose innermost two dimensions form MxN matrices.

  • offset (int) –

    offset specifying the off-diagonal relative to the main diagonal.

    • offset = 0: the main diagonal.

    • offset > 0: off-diagonal above the main diagonal.

    • offset < 0: off-diagonal below the main diagonal.

    Default: 0.

Returns

out (array) – an array containing the diagonals and whose shape is determined by removing the last two dimensions and appending a dimension equal to the size of the resulting diagonals. The returned array must have the same data type as x.