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.

Large Linear Algebra

More
6 years 2 months ago #391 by hvwahl
Large Linear Algebra was created by hvwahl
Hi,

I am trying to compute the eigenvalues of an NGSolve matrix originating from a bilinear form B. My attempt has been to follow the documentation and to create an numpy array using B.mat.NumPy() and B.NumPy(). However this gives me the error message

AttributeError: 'ngsolve.la.SparseMatrixd' object has no attribute 'NumPy'

and

AttributeError: 'ngsolve.comp.BilinearForm' object has no attribute 'NumPy'

respectively.

How can I create a numpy array using NGS-Py so that I work with the matrix using numpy?

Best Wishes,
Henry
More
6 years 2 months ago #392 by cwinters
Replied by cwinters on topic Large Linear Algebra
Hi Henry,

you should follow this reference .
Getting a scipy matrix and calculating the eigenvalues can be done with the following lines.
Code:
import scipy.sparse as sp from scipy.linalg import eig rows,cols,vals = B.mat.COO() M = sp.csr_matrix((array(vals),(array(rows),array(cols)))) # M = sp.csr_matrix((vals,(rows,cols))) lam = eig(M.todense())
If your version of scipy is not new enough (like in my case 0.17.0) you have to cast the output of COO() to a python array.

Best,
Christoph
The following user(s) said Thank You: hvwahl
More
6 years 2 months ago #393 by hvwahl
Replied by hvwahl on topic Large Linear Algebra
Hi Christoph,

Thank you for your quick response! Your code runs perfectly :)

I'm sorry I missed that part of the documentation.

Best wishes,
Henry
Time to create page: 0.150 seconds