mindspore.scipy.linalg.block_diag

View Source On Gitee
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]]

Note

block_diag is not supported on Windows platform yet.

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:

GPU CPU

Examples

>>> import numpy as onp
>>> from mindspore 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'))
>>> print(block_diag(A, B, C))
[[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]]
>>> print(block_diag(A, P, B, C))
[[1 0 0 0 0 0 0 0]
 [0 1 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0]
 [0 0 0 0 3 4 5 0]
 [0 0 0 0 6 7 8 0]
 [0 0 0 0 0 0 0 7]]