@staticmethod<EOL><INDENT>def scale_interpolation(interp, mask=None, weights=None):<DEDENT>
if sps.issparse(interp): interp = interp.tocsr().copy()<EOL>if weights is None and mask is None: return interp<EOL>(m,n) = interp.shape <EOL>if weights is None:           weights = np.ones(n, dtype=np.float)<EOL>elif np.shape(weights) == (): weights = np.full(n, weights, dtype=np.float)<EOL>else:                         weights = np.array(weights, dtype=np.float)<EOL>if mask is not None:<EOL><INDENT>mask = self.mask(mask, indices=True)<EOL>nmask = np.setdiff1d(np.arange(n), mask)<EOL>weights[nmask] = np.nan<EOL><DEDENT>nansq = np.logical_not(np.isfinite(flattest(interp.sum(axis=<NUM_LIT:1>))))<EOL>interp.data[~np.isfinite(interp.data)] = <NUM_LIT:0><EOL>heaviest = flattest(interp.argmax(axis=<NUM_LIT:1>))<EOL>hvals = interp[(np.arange(m), heaviest)]<EOL>hnots = np.isclose(hvals, <NUM_LIT:0>) | ~np.isfinite(weights[heaviest]) | nansq<EOL>whnan = np.where(hnots)[<NUM_LIT:0>]<EOL>weights[~np.isfinite(weights)] = <NUM_LIT:0><EOL>interp *= sps.diag(weights)<EOL>rsums = flattest(interp.sum(axis=<NUM_LIT:1>))<EOL>if not np.isclose(rsums, <NUM_LIT:1>).all(): interp = sps.diag(zinv(rsums)).dot(interp)<EOL>if len(whnan) > <NUM_LIT:0>: interp[(np.zeros(len(whnan), dtype=np.int), whnan)] = np.nan<EOL>interp.eliminate_zeros()<EOL>return interp<EOL>
Mesh.scale_interpolation(interp) yields a duplicate of interp in which all rows of the
  interpolation matrix have a sum of 1 or contain a nan element; those rows that correspond
  to interpolation points that are either not in the mask or have zero weight contributing
  to them will have a nan value somewhere that indicates that the interpolated value should
  always be nan.
Mesh.scale_interpolation(interp, mask) additionally applies the given mask to the
  interpolation matrix; any interpolation point whose nearest neighbor is a vertex outside
  of the given mask will be assigned a value of numpy.nan upon interpolation with the
  resulting interpolation matrix.
Mesh.scale_interpolation(interp, mask, weights) additionally applies the given vertex 
  weights to the interpolation matrix.

The value mask may be specified as either None (no interpolation), a boolean array with the
same number of elements as there are columns in interp, or a list of indices. The values in
the mask are considered valid while the values not in the mask are considered invalid. The
string value 'all' is also a valid mask (equivalent to no mask, or all elements in the
mask).

The interp argument should be a scipy.sparse.*_matrix; the object will not be modified
in-place except to run eliminate_zeros(), and the returned matrix will always be of the
csr_matrix type. Typical usage would be:
interp_matrix = scipy.sparse.lil_matrix((n, self.vertex_count))
# create your interpolation matrix here...
return Mesh.rescale_interpolation(interp_matrix, mask_arg, weights_arg)