Transform dolfinx assemble matrix to numpy array

It’s probably the dense mode that’s killing you. You can convert to a sparse CSR matrix using something like

A = assemble_matrix(a, [bc])
A.assemble()
assert isinstance(A, PETSc.Mat)
ai, aj, av = A.getValuesCSR()
Asp = csr_matrix((av, aj, ai))