Large Linear Algebra

More
6 years 9 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 9 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 9 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.096 seconds