code: def smatrix_from_3d_idx(ijk, nn=18):
      """Create a sparse adjacency matrix from 3d index system
  
      Parameters
      ----------
      idx:array of shape (n_samples, 3), type int
          indexes of certain positions in a 3d space
      nn: int, optional
          3d neighboring system to be chosen within {6, 18, 26}
  
      Returns
      -------
      coo_mat: a sparse coo matrix,
               adjacency of the neighboring system
  
      """
      G = wgraph_from_3d_grid(ijk, nn)
      return G.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 2 for calling a global function with example usage: smatrix_from_3d_idx(ijk, nn) and returns: G