diag edit page

convert rank 1 or rank 0 tensor into diagonal rank 2 tensor

Description

If the input tensor has rank 0 or 1 the resulting tensor will have rank 2 with the diagonal filled with the input tensor elements. If the input tensor has rank at least two the resulting tensor has rank 1 with elements being the diagonal of the input tensor.

Synatx

T = diag(T)

Syntax

T = diag(T)

Input

T tensor

Output

T tensor

See also

tensor.trace