nodes: 0, module; 1, function_definition; 2, function_name:nd_sort_samples; 3, parameters; 4, block; 5, identifier:samples; 6, expression_statement; 7, comment:# Check the shape of the sample list.; 8, assert_statement; 9, comment:# Build a KD-tree on the samples.; 10, expression_statement; 11, comment:# Compute the distances.; 12, expression_statement; 13, return_statement; 14, comment:"""
      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.
  
      """; 15, comparison_operator:len(samples.shape) == 2; 16, assignment; 17, assignment; 18, identifier:i; 19, call; 20, integer:2; 21, identifier:tree; 22, call; 23, pattern_list; 24, call; 25, identifier:len; 26, argument_list; 27, identifier:cKDTree; 28, argument_list; 29, identifier:d; 30, identifier:i; 31, attribute; 32, argument_list; 33, attribute; 34, identifier:samples; 35, identifier:tree; 36, identifier:query; 37, subscript; 38, keyword_argument; 39, identifier:samples; 40, identifier:shape; 41, identifier:samples; 42, integer:0; 43, identifier:k; 44, call; 45, identifier:len; 46, argument_list; 47, identifier:samples
code: def nd_sort_samples(samples):
      """
      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.
  
      """
      # 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