mindspore.ops.diagflat

mindspore.ops.diagflat(input, offset=0)[source]

Create a 2-D Tensor which diagonal is the flattened input .

Parameters
  • input (Tensor) – Input Tensor, which is flattened and set as the diagonal of the output.

  • offset (int, optional) –

    offset controls which diagonal to choose. Default: 0.

    • When offset is zero, the diagonal chosen is the main diagonal.

    • When offset is a positive integer, the diagonal chosen is up the main diagonal.

    • When offset is a negative integer, the diagonal chosen is down the main diagonal.

Returns

The 2-D Tensor, whose diagonal is the flattened input.

Raises
Supported Platforms:

Ascend GPU CPU

Examples

>>> x = Tensor([1, 2], mindspore.float32)
>>> output = ops.diagflat(x, 1)
>>> print(output)
[[0. 1. 0.]
 [0. 0. 2.]
 [0. 0. 0.]]