Going to Scipy/numpy error message


I have a matrix defined on a mesh as given below.
I want to make it into a larger system by placing my matrix a into a block matrix
My attempt is [code] a = BilinearForm(fes)
a += grad(u)*grad(v)*dx

length = a.mat.height
Z = sp.coo_matrix((length, length))
I = sp.identity(length)
B1a = sp.hstack([a.mat, Z])
B1b = sp.hstack([Z, I])
B1 = sp.vstack([B1a, B1b])[/code]
however this results in the following error message:
blocks[0,:] has incompatible row dimensions. Got blocks[0,1].shape[0] == 358240, expected 1.

How to I get around this error

In the code snippet you posted, it looks like you may not have assembled the BilinearForm before acessing its matrix property.

a = BilinearForm(fes) a += grad(u)*grad(v)*dx a.Assemble() # <-- need to do this before accessing the matrix length = a.mat.height

Also, the NGSolve sparse matrix can’t be used directly in scipy sparse like this

B1a = sp.hstack([a.mat, Z])

You might want to take a look at this: https://docu.ngsolve.org/latest/how_to/howto_numpy.html