code: def _make_edges_and_weights(X, mask_img):
      """Compute the weights to all edges in the mask.
  
      Parameters
      ----------
      X : ndarray, shape = [n_samples, n_features]
          Training data.
  
      mask_img : Niimg-like object
          Object used for masking the data.
  
      Returns
      -------
      edges : ndarray
          Array containing [edges_deep, edges_right, edges_down]
  
      weights : ndarray
          Weights corresponding to all edges in the mask.
          shape: (n_edges,).
  
      """
      mask = get_data(mask_img)
      shape = mask.shape
      n_vertices = np.prod(shape)
  
      # Indexing each voxel
      vertices = np.arange(n_vertices).reshape(shape)
  
      weights_unmasked = _compute_weights(X, mask_img)
  
      edges_unmasked = _make_3d_edges(vertices, is_mask=False)
      edges_mask = _make_3d_edges(mask, is_mask=True)
  
      # Apply mask to edges and weights
      weights = np.copy(weights_unmasked[edges_mask])
      edges = np.copy(edges_unmasked[:, edges_mask])
  
      # Reorder the indices of the graph
      max_index = edges.max()
      order = np.searchsorted(
          np.unique(edges.ravel()), np.arange(max_index + 1)
      )
      edges = order[edges]
  
      return edges, weights
  
imports: import warnings
  import numpy
  from joblib import Memory
  from nibabel import Nifti1Image
  from scipy.sparse import coo_matrix, csgraph, dia_matrix
  from sklearn.base import BaseEstimator, ClusterMixin, TransformerMixin
  from sklearn.utils import check_array
  from sklearn.utils.validation import check_is_fitted
  from nilearn._utils import fill_doc
  from nilearn.image import get_data
  from nilearn.masking import unmask_from_to_3d_array
label_desc: Use image node_id 3 for calling a global function with example usage: _make_edges_and_weights(X, mask_img) and returns: edges,  weights