diagonal — Python array API standard 2024.12 documentation (original) (raw)

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

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

Parameters:

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.