I need help in building a block tridiagonal matrix using scipy sparse. What I mean by that is for a square matrix B, I need to create [[B I 0 0 0] [I B I 0 0] [0 I B I 0] [0 0
Solution 1:
Solved it!
I just used scipy.sparse.bmat in conjunction with list comprehensions.
A = sparse.bmat([[B if i == j else np.eye(n) ifabs(i-j)==1elseNonefor i inrange(n)]
for j inrange(n)], format='bsr')
Where B is an nxn matrix.
Share
Post a Comment
for "Tridiagonal Block Matrix Using Scipy.sparse"
Post a Comment for "Tridiagonal Block Matrix Using Scipy.sparse"