def simplex_summation_matrix(simplices, weight=None, inverse=False):
simplices = np.asarray(simplices)<EOL>n = np.max(simplices) + <NUM_LIT:1><EOL>(d,m) = simplices.shape<EOL>rng = range(m)<EOL>if inverse:<EOL><INDENT>if weight is None: f = sps.csr_matrix<EOL>else:<EOL><INDENT>nrng = range(n)<EOL>ww = sps.csr_matrix((weight, (nrng, nrng)), shape=(n,n), dtype=np.float)<EOL>f = lambda *args,**kwargs: ww.dot(sps.csc_matrix(*args,**kwargs))<EOL><DEDENT>s = f((np.ones(d*m, dtype=np.int),<EOL>(np.concatenate([rng for _ in range(d)]), np.concatenate(simplices))),<EOL>shape=(m,n),<EOL>dtype=np.int)<EOL><DEDENT>else:<EOL><INDENT>s = sps.csr_matrix(<EOL>(np.ones(d*m, dtype=np.int),<EOL>(np.concatenate(simplices), np.concatenate([rng for _ in range(d)]))),<EOL>shape=(n,m),<EOL>dtype=np.int)<EOL>if weight is not None:<EOL><INDENT>s = s.dot(sps.csc_matrix((weight, (rng, rng)), shape=(m,m), dtype=np.float))<EOL><DEDENT><DEDENT>return s<EOL>
simplex_summation_matrix(mtx) yields a scipy sparse array matrix that, when dotted with a
  column vector of length m (where m is the number of simplices described in the simplex matrix,
  mtx), yields a vector of length n (where n is the number of vertices in the simplex mesh); the
  returned vetor is the sum over each vertex, of the faces to which it belongs.

The matrix mtx must be oriented such that the first dimension (rows) corresponds to the vertices
of the simplices and the second dimension (columns) corresponds to simplices themselves.

The optional argument weight may specify a weight for each face, in which case the summation is
a weighted sum instead of a flat sum.

The optional argument inverse=True may be given to indicate that the inverse summation matrix
(summation of the vertices onto the simplices) should be returned.