code: def wgraph_from_3d_grid(xyz, k=18):
      """Create graph as the set of topological neighbours
      of the three-dimensional coordinates set xyz,
      in the k-connectivity scheme
  
      Parameters
      ----------
      xyz: array of shape (nsamples, 3) and type np.int_,
      k = 18: the number of neighbours considered. (6, 18 or 26)
  
      Returns
      -------
      the WeightedGraph instance
      """
      if xyz.shape[1] != 3:
          raise ValueError("xyz should have shape n * 3")
      if k not in [6, 18, 26]:
          raise ValueError("k should be equal to 6, 18 or 26")
  
      i, j, d = graph_3d_grid(xyz, k)
      edges = np.vstack((i, j)).T
      return WeightedGraph(xyz.shape[0], edges, d)
  
imports: import numpy
  from scipy.sparse import coo_matrix
label_desc: Use image node_id 9 for calling a global function with example usage: wgraph_from_3d_grid(xyz, k) and returns: WeightedGraph