code: def _mask_edges_weights(edges, weights, mask):
      """Remove edges of the graph connected to masked nodes, \
      as well as corresponding weights of the edges."""
      mask0 = np.hstack(
          (
              mask[:, :, :-1].ravel(),
              mask[:, :-1].ravel(),
              mask[:-1].ravel(),
          )
      )
      mask1 = np.hstack(
          (
              mask[:, :, 1:].ravel(),
              mask[:, 1:].ravel(),
              mask[1:].ravel(),
          )
      )
      ind_mask = np.logical_and(mask0, mask1)
      edges, weights = edges[:, ind_mask], weights[ind_mask]
      max_node_index = edges.max()
      # Reassign edges labels to 0, 1, ... edges_number - 1
      order = np.searchsorted(
          np.unique(edges.ravel()), np.arange(max_node_index + 1)
      )
      edges = order[edges.astype(np.int64)]
      return edges, weights
  
file_path: nilearn/nilearn/_utils/segmentation.py
imports: import warnings
  import numpy
  from scipy import ndimage, sparse
  from scipy.sparse.linalg import cg
  from sklearn.utils import as_float_array
label_desc: Use image node_id 7 for calling a global function with example usage: _mask_edges_weights(edges, weights, mask) and returns: edges,  weights