mindspore.scipy.linalg.block_diag

mindspore.scipy.linalg.block_diag(*arrs)[源代码]

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]]

说明

block_diag is not supported on Windows platform yet.

参数

arrs (list) – up to 2-D Input Tensors. A 1-D Tensor or a 2-D Tensor with shape \((1,n)\).

返回

Tensor with A, B, C, … on the diagonal which has the same dtype as A.

异常

ValueError – If there are Tensors with dimensions higher than 2 in all arguments.

Supported Platforms:

GPU CPU

样例

>>> 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'))
>>> 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]]