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’
AttributeError: ‘ngsolve.comp.BilinearForm’ object has no attribute ‘NumPy’
How can I create a numpy array using NGS-Py so that I work with the matrix using numpy?
you should follow this reference.
Getting a scipy matrix and calculating the eigenvalues can be done with the following lines.
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.
Thank you for your quick response! Your code runs perfectly
I’m sorry I missed that part of the documentation.