Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Going to Scipy/numpy error message

More
2 years 10 months ago #3798 by ajf367
Hello,

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])
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
More
2 years 10 months ago #3832 by ddrake
In the code snippet you posted, it looks like you may not have assembled the BilinearForm before acessing its matrix property.
Code:
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
Code:
B1a = sp.hstack([a.mat, Z])

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

Best,
Dow
Time to create page: 0.126 seconds