mindspore.ops.diagflat
- mindspore.ops.diagflat(input, offset=0)[source]
If input is a vector (1-D tensor), then returns a 2-D square tensor with the elements of input as the diagonal, If input is a tensor with more than one dimension, then returns a 2-D tensor with diagonal elements equal to a flattened input.
- Parameters
- Returns
Tensor
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> mindspore.ops.diagflat(mindspore.tensor([1, 2, 3])) Tensor(shape=[3, 3], dtype=Int64, value= [[1, 0, 0], [0, 2, 0], [0, 0, 3]]) >>> mindspore.ops.diagflat(mindspore.tensor([1, 2, 3]), 1) Tensor(shape=[4, 4], dtype=Int64, value= [[0, 1, 0, 0], [0, 0, 2, 0], [0, 0, 0, 3], [0, 0, 0, 0]]) >>> mindspore.ops.diagflat(mindspore.tensor([[1, 2], [3, 4]])) Tensor(shape=[4, 4], dtype=Int64, value= [[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]])