code: def grid_domain_from_binary_array(mask, affine=None, nn=0):
      """Return a NDGridDomain from an n-d array
  
      Parameters
      ----------
      mask: np.array instance
            a supposedly boolean array that represents the domain
      affine: np.array, optional
              affine transform that maps the array coordinates
              to some embedding space
              by default, this is np.eye(dim+1, dim+1)
      nn: neighboring system considered
          unused at the moment
  
      """
      dim = len(mask.shape)
      shape = mask.shape
      if affine is None:
          affine = np.eye(dim + 1)
  
      mask = mask > 0
      ijk = np.array(np.where(mask)).T
      vol = np.absolute(np.linalg.det(affine[:3, 0:3])) * np.ones(
          np.sum(mask)
      )
      topology = smatrix_from_nd_idx(ijk, nn)
      return NDGridDomain(dim, ijk, shape, affine, vol, topology)
  
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 10 for calling a global function with example usage: grid_domain_from_binary_array(mask, affine, nn) and returns: NDGridDomain