code: def smatrix_from_3d_array(mask, nn=18):
      """Create a sparse adjacency matrix from an array
  
      Parameters
      ----------
      mask : 3d array,
             input array, interpreted as a mask
      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
  
      """
      ijk = np.array(np.where(mask)).T
      return smatrix_from_3d_idx(ijk, nn)
  
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 1 for calling a global function with example usage: smatrix_from_3d_array(mask, nn) and returns: smatrix_from_3d_idx