mindspore.ops.block_diag
- mindspore.ops.block_diag(*inputs)[源代码]
基于输入tensor创建块对角矩阵。
- 参数:
inputs (Tensor) - 一个或多个tensor,tensor的维度应该为0、1或2。
- 返回:
二维tensor。所有输入tensor按顺序排列,使其左上角和右下角对角线相邻,其他所有元素都置零。
- 支持平台:
Ascend
GPU
CPU
样例:
>>> import mindspore >>> x1 = mindspore.tensor([[4], [3], [2]], mindspore.int32) >>> x2 = mindspore.tensor([7, 6, 5], mindspore.int32) >>> x3 = mindspore.tensor(1, mindspore.int32) >>> x4 = mindspore.tensor([[5, 4, 3], [2, 1, 0]], mindspore.int32) >>> x5 = mindspore.tensor([[8, 7], [7, 8]], mindspore.int32) >>> out = mindspore.ops.block_diag(x1, x2, x3, x4, x5) >>> print(out.asnumpy()) [[4 0 0 0 0 0 0 0 0 0] [3 0 0 0 0 0 0 0 0 0] [2 0 0 0 0 0 0 0 0 0] [0 7 6 5 0 0 0 0 0 0] [0 0 0 0 1 0 0 0 0 0] [0 0 0 0 0 5 4 3 0 0] [0 0 0 0 0 2 1 0 0 0] [0 0 0 0 0 0 0 0 8 7] [0 0 0 0 0 0 0 0 7 8]]