diagflat#

ivy.diagflat(x, /, *, offset=0, padding_value=0, align='RIGHT_LEFT', num_rows=-1, num_cols=-1, out=None)[source]#

Return a two-dimensional array with the flattened input as a diagonal.

Parameters:
  • x (Union[Array, NativeArray]) – Input data, which is flattened and set as the k-th diagonal of the output.

  • k – Diagonal to set. Positive value means superdiagonal, 0 refers to the main diagonal, and negative value means subdiagonal.

  • out (Optional[Union[Array, NativeArray]], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – The 2-D output array.

Examples

With ivy.Array inputs:

>>> x = ivy.array([[1,2], [3,4]])
>>> ivy.diagflat(x)
ivy.array([[1, 0, 0, 0],
           [0, 2, 0, 0],
           [0, 0, 3, 0],
           [0, 0, 0, 4]])
>>> x = ivy.array([1,2])
>>> ivy.diagflat(x, k=1)
ivy.array([[0, 1, 0],
           [0, 0, 2],
           [0, 0, 0]])
Array.diagflat(self, /, *, offset=0, padding_value=0, align='RIGHT_LEFT', num_rows=-1, num_cols=-1, out=None)[source]#

ivy.Array instance method variant of ivy.diagflat. This method simply wraps the function, and so the docstring for ivy.diagflat also applies to this method with minimal changes.

Return type:

Array

Examples

>>> x = ivy.array([1,2])
>>> x.diagflat(k=1)
ivy.array([[0, 1, 0],
           [0, 0, 2],
           [0, 0, 0]])
Container.diagflat(self, /, *, offset=0, padding_value=0, align='RIGHT_LEFT', num_rows=-1, num_cols=-1, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.diagflat. This method simply wraps the function, and so the docstring for ivy.diagflat also applies to this method with minimal changes.

Return type:

Container

Examples

>>> x = ivy.Container(a=[1,2])
>>> ivy.diagflat(x, k=1)
{
    a: ivy.array([[0, 1, 0],
                  [0, 0, 2],
                  [0, 0, 0]])
}