- edited description
Getting Numpy array out of PETSc Mat
Issue #26
resolved
I am trying to get a numpy array out of a PETSc.Mat. For PETSc.Vec objects, b.array does the trick.
But if c is a PETSc.Mat object, getDenseArray() gives the following error
>>> c.getDenseArray()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Mat.pyx", line 1287, in petsc4py.PETSc.Mat.getDenseArray (src/petsc4py.PETSc.c:122734)
petsc4py.PETSc.Error: error code 56
[0] MatDenseGetArray() line 1499 in /fusion/gpfs/home/jlarson/software/petsc-3.5.3/src/mat/impls/dense/seq/dense.c
[0] No support for this operation for this object type
[0] Cannot locate function MatDenseGetArray_C in object
Is there a way to get the full matrix out?
Comments (4)
-
reporter -
What matrix type are you using?
Mat.getDenseArray()
only works for theMATDENSE
matrix type. You have to either convert your matrix to dense format (usingc_dense = c.convert("dense")
), of in case of aMATAIJ
matrix, useai, aj, av = c.getValuesCSR()
to get three arrays in CSR format. -
reporter Yes. Converting to a dense matrix works. Thank you.
-
- changed status to resolved
- Log in to comment