nodes: 0, module; 1, function_definition; 2, function_name:inverse_cdf; 3, parameters; 4, block; 5, identifier:su; 6, identifier:W; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, for_statement; 13, return_statement; 14, comment:"""Inverse CDF algorithm for a finite distribution. 
  
          Parameters
          ----------
          su: (M,) ndarray
              M sorted uniform variates (i.e. M ordered points in [0,1]). 
          W: (N,) ndarray 
              a vector of N normalized weights (>=0 and sum to one)
  
          Returns
          ------- 
          A: (M,) ndarray
              a vector of M indices in range 0, ..., N-1
      """; 15, assignment; 16, assignment; 17, assignment; 18, assignment; 19, identifier:n; 20, call; 21, block; 22, identifier:A; 23, identifier:j; 24, integer:0; 25, identifier:s; 26, subscript; 27, identifier:M; 28, subscript; 29, identifier:A; 30, call; 31, identifier:range; 32, argument_list; 33, while_statement; 34, expression_statement; 35, identifier:W; 36, integer:0; 37, attribute; 38, integer:0; 39, attribute; 40, argument_list; 41, identifier:M; 42, comparison_operator:su[n] > s; 43, block; 44, assignment; 45, identifier:su; 46, identifier:shape; 47, identifier:np; 48, identifier:empty; 49, identifier:M; 50, string; 51, subscript; 52, identifier:s; 53, expression_statement; 54, expression_statement; 55, subscript; 56, identifier:j; 57, string_content:int; 58, identifier:su; 59, identifier:n; 60, augmented_assignment; 61, augmented_assignment; 62, identifier:A; 63, identifier:n; 64, identifier:j; 65, integer:1; 66, identifier:s; 67, subscript; 68, identifier:W; 69, identifier:j
code: def inverse_cdf(su, W):
      """Inverse CDF algorithm for a finite distribution. 
  
          Parameters
          ----------
          su: (M,) ndarray
              M sorted uniform variates (i.e. M ordered points in [0,1]). 
          W: (N,) ndarray 
              a vector of N normalized weights (>=0 and sum to one)
  
          Returns
          ------- 
          A: (M,) ndarray
              a vector of M indices in range 0, ..., N-1
      """
      j = 0
      s = W[0]
      M = su.shape[0]
      A = np.empty(M, 'int')
      for n in range(M):
          while su[n] > s:
              j += 1
              s += W[j]
          A[n] = j
      return A