I have a block-diagonal sparse matrix in python with hundreds of thousands to millions of rows, but with many different sized blocks between 1x1 and 6x6; for example plt.spy() on a submatrix: 
I need the inverse of this matrix without looping in python (too slow). I should be able to extract the block diagonal to get a list of 2d arrays (have not actually implemented this yet), but even then I cannot figure out how to apply, e.g., np.linalg.inv() to a bunch of different size matrices. Any ideas on inverting in sparse matrix form or via a list of diagonal blocks??