block_diag(*arrs)
Given the inputs A
, B
and C
, the output will have these arrays arranged on the diagonal:
[[A, 0, 0], [0, B, 0], [0, 0, C]]
If all the input arrays are square, the output is known as a block diagonal matrix.
Empty sequences (i.e., array-likes of zero size) will not be ignored. Noteworthy, both [] and [[]] are treated as matrices with shape (1,0)
.
Input arrays. A 1-D array or array_like sequence of length :None:None:`n`
is treated as a 2-D array with shape (1,n)
.
Create a block diagonal matrix from provided arrays.
>>> from scipy.linalg import block_diag
... A = [[1, 0],
... [0, 1]]
... B = [[3, 4, 5],
... [6, 7, 8]]
... C = [[7]]
... P = np.zeros((2, 0), dtype='int32')
... block_diag(A, B, C) array([[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) array([[1, 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, 6, 7, 8, 0], [0, 0, 0, 0, 0, 7]])
>>> block_diag(1.0, [2, 3], [[4, 5], [6, 7]]) array([[ 1., 0., 0., 0., 0.], [ 0., 2., 3., 0., 0.], [ 0., 0., 0., 4., 5.], [ 0., 0., 0., 6., 7.]])See :
The following pages refer to to this document either explicitly or contain code examples using this.
scipy.linalg._special_matrices.block_diag
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them