How to create a Matrix (dolfin.cpp.la.Matrix) from Vectors (dolfin.cpp.la.Vector)?

As always, you should second-guess any procedure that results in a dense matrix, but, if it’s really necessary, one approach could be the following:

from dolfin import *
from petsc4py import PETSc
from numpy import array

# Get some dolfin.cpp.la.Vector objects:
mesh = UnitIntervalMesh(10)
V = FunctionSpace(mesh,"DG",0)
v = TestFunction(V)
v1 = assemble(Constant(1.0)*v*dx)
v2 = assemble(Constant(2.0)*v*dx)
v3 = assemble(Constant(3.0)*v*dx)

# Put them all into a NumPy matrix:
npMat = array([v1.get_local(),
               v2.get_local(),
               v3.get_local()]).transpose()
print(npMat)

# Create a PETSc dense matrix, with the
# petsc4py API, then wrap that as a
# dolfin.cpp.la.PETScMatrix object:
petMat = PETSc.Mat()
petMat.createDense(npMat.shape,array=npMat)
petMat.setUp()
mat = PETScMatrix(petMat)

print(mat.array())