3d Numpy Array Into Block Diagonal Matrix
I am looking for a way to convert a nXaXb numpy array into a block diagonal matrix. I have already came across scipy.linalg.block_diag, the down side of which (for my case) is it r
Solution 1:
Try using block_diag(*a)
. See example below:
In [9]: paste
import numpy as np
a = np.random.rand(3,2,2)
from scipy.linalg import block_diag
b = block_diag(a[0], a[1],a[2])
c = block_diag(*a)
b == c
## -- End pasted text --
Out[9]:
array([[ True, True, True, True, True, True],
[ True, True, True, True, True, True],
[ True, True, True, True, True, True],
[ True, True, True, True, True, True],
[ True, True, True, True, True, True],
[ True, True, True, True, True, True]], dtype=bool)
Post a Comment for "3d Numpy Array Into Block Diagonal Matrix"