Large Linear Algebra

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

Attachment: Eigenvalues-conv_2018-02-23.py

Hi Henry,

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.

Best,
Christoph

Hi Christoph,

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

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

Best wishes,
Henry