Hi, the following uses the fact that for DG0 space(a natural space for a derivative of CG1) the mass matrix is diagonal with the entries being volumes of the cells. Thus you can actually assemble the vector representing the gradient directly and then use it to define function.
from dolfin import *
import numpy as np
mesh = UnitCubeMesh(20, 20, 20)
V = FunctionSpace(mesh, 'CG', 1)
f = Function(V)
f_vec = f.vector()
f_vec.set_local(np.random.rand(f_vec.local_size()))
f_vec.apply('insert')
Q = VectorFunctionSpace(mesh, 'DG', 0)
# Grad via projection
p, q = TrialFunction(Q), TestFunction(Q)
L = inner(grad(f), q)*dx
M = assemble(inner(p, q)*dx)
b = assemble(L)
grad_f0 = Function(Q)
x0 = grad_f0.vector()
solve(M, x0, b)
# Assemble the action of Minv onto the rhs - no mass matrix needed
MinvL = (1/CellVolume(mesh))*inner(grad(f), q)*dx
x = assemble(MinvL)
print (x - x0).norm('linf')
# You can define a function now
grad_f = Function(Q, x)
Why do you want to represent the gradient in DG1?