code: def nd_sort_samples(samples):
      
      # Check the shape of the sample list.
      assert len(samples.shape) == 2
  
      # Build a KD-tree on the samples.
      tree = cKDTree(samples)
  
      # Compute the distances.
      d, i = tree.query(samples[0], k=len(samples))
      return i
docs: Sort an N-dimensional list of samples using a KDTree.
  
      :param samples: ``(nsamples, ndim)``
          The list of samples. This must be a two-dimensional array.
  
      :returns i: ``(nsamples,)``
          The list of indices into the original array that return the correctly
          sorted version.