code: def reduce_coo_matrix(mat, mask):
      """Reduce a supposedly coo_matrix to the vertices in the mask
  
      Parameters
      ----------
      mat: sparse coo_matrix,
           input matrix
      mask: boolean array of shape mat.shape[0],
            desired elements
  
      """
      G = wgraph_from_coo_matrix(mat)
      K = G.subgraph(mask)
      if K is None:
          return None
      return K.to_coo_matrix()
  
imports: import numpy
  import scipy.sparse
  from nibabel import Nifti1Image, load, save
  from nipy.algorithms.graph import WeightedGraph, wgraph_from_3d_grid, wgraph_from_coo_matrix
  from nipy.io.nibcompat import get_affine, get_header
label_desc: Use image node_id 7 for calling a global function with example usage: reduce_coo_matrix(mat, mask) and returns: K, None