mindspore.ops.diagflat
- mindspore.ops.diagflat(input, offset=0)[源代码]
如果input是一维Tensor,则返回input作为对角线的二维Tensor,如果input是大于等于二维的Tensor,则将input展开后作为对角线的二维Tensor。
- 参数:
input (Tensor) - 输入Tensor。
offset (int, 可选) - 对角线偏移量。默认值:
0
。当 offset 是正整数时,对角线向上方偏移。
当 offset 是负整数时,对角线向下方偏移。
- 返回:
Tensor
- 支持平台:
Ascend
GPU
CPU
样例:
>>> 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]])