mindspore.scipy.linalg.block_diag
- mindspore.scipy.linalg.block_diag(*arrs)[source]
Create a block diagonal matrix from provided arrays.
Given the list of Tensors A, B, and C, the output will have these Tensors arranged on the diagonal:
[[A, 0, 0], [0, B, 0], [0, 0, C]]
- Parameters
arrs (list) – up to 2-D Input Tensors. A 1-D Tensor or a 2-D Tensor with shape \((1,n)\).
- Returns
Tensor with A, B, C, … on the diagonal which has the same dtype as A.
- Raises
ValueError – If there are Tensors with dimensions higher than 2 in all arguments.
- Supported Platforms:
CPU
GPU
Examples
>>> import numpy as onp >>> from mindspore.common import Tensor >>> from mindspore.scipy.linalg import block_diag >>> A = Tensor(onp.array([[1, 0], [0, 1]])) >>> B = Tensor(onp.array([[3, 4, 5], [6, 7, 8]])) >>> C = Tensor(onp.array([[7]])) >>> P = Tensor(onp.zeros((2, ), dtype='int32')) >>> block_diag(A, B, C) Tensor(shape=[5, 6], dtype=Int64, value= [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 3, 4, 5, 0], [0, 0, 6, 7, 8, 0], [0, 0, 0, 0, 0, 7]]) >>> block_diag(A, P, B, C) Tensor(shape=[6, 8], dtype=Int64, value= [[1, 0, 0 ... 0, 0, 0], [0, 1, 0 ... 0, 0, 0], [0, 0, 0 ... 0, 0, 0], [0, 0, 0 ... 4, 5, 0], [0, 0, 0 ... 7, 8, 0], [0, 0, 0 ... 0, 0, 7]])