This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to get Matrix diagonal?

+1 vote

How do I get the diagonal of a Matrix into a numpy array?

asked Nov 25, 2014 by chaffra FEniCS User (1,830 points)

1 Answer

+2 votes

For PETSc backend and dolfin matrix A:

diagonal = as_backend_type(A).mat().getDiagonal().array
answered Nov 26, 2014 by mikael-mortensen FEniCS Expert (29,340 points)

wrong comment: I found my mistake. It's

.array

and not

.array()
...