code: def grid_to_graph(
      n_x,
      n_y,
      n_z=1,
      *,
      mask=None,
      return_as=sparse.coo_matrix,
      dtype=int,
  ):
      """Graph of the pixel-to-pixel connections.
  
      Edges exist if 2 voxels are connected.
  
      Parameters
      ----------
      n_x : int
          Dimension in x axis.
      n_y : int
          Dimension in y axis.
      n_z : int, default=1
          Dimension in z axis.
      mask : ndarray of shape (n_x, n_y, n_z), dtype=bool, default=None
          An optional mask of the image, to consider only part of the
          pixels.
      return_as : np.ndarray or a sparse matrix class, \
              default=sparse.coo_matrix
          The class to use to build the returned adjacency matrix.
      dtype : dtype, default=int
          The data of the returned sparse matrix. By default it is int.
  
      Returns
      -------
      graph : np.ndarray or a sparse matrix class
          The computed adjacency matrix.
  
      Notes
      -----
      For scikit-learn versions 0.14.1 and prior, return_as=np.ndarray was
      handled by returning a dense np.matrix instance.  Going forward, np.ndarray
      returns an np.ndarray, as expected.
  
      For compatibility, user code relying on this method should wrap its
      calls in ``np.asarray`` to avoid type issues.
      """
      return _to_graph(
          n_x, n_y, n_z, mask=mask, return_as=return_as, dtype=dtype
      )
  
imports: from itertools import product
  from numbers import Integral, Number, Real
  import numpy
  from numpy.lib.stride_tricks import as_strided
  from scipy import sparse
  from ..base import BaseEstimator, TransformerMixin, _fit_context
  from ..utils import check_array, check_random_state
  from ..utils._param_validation import Hidden, Interval, RealNotInt, validate_params
label_desc: Use image node_id 6 for calling a global function with example usage: grid_to_graph(n_x, n_y, n_z) and returns: _to_graph