nodes: 0, module; 1, function_definition; 2, function_name:unique; 3, parameters; 4, type; 5, block; 6, identifier:arr; 7, default_parameter; 8, attribute; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, while_statement; 13, return_statement; 14, identifier:tolerance; 15, float:1e-6; 16, identifier:np; 17, identifier:ndarray; 18, comment:"""Return unique elements in 1D array, within tolerance.
  
      Parameters
      ----------
      arr : array_like
          Input array. This will be flattened if it is not already 1D.
      tolerance : number (optional)
          The tolerance for uniqueness.
  
      Returns
      -------
      array
          The sorted unique values.
      """; 19, assignment; 20, assignment; 21, comparison_operator:len(arr) > 0; 22, block; 23, call; 24, identifier:arr; 25, call; 26, identifier:unique; 27, list; 28, call; 29, integer:0; 30, expression_statement; 31, expression_statement; 32, expression_statement; 33, expression_statement; 34, expression_statement; 35, attribute; 36, argument_list; 37, identifier:sorted; 38, argument_list; 39, identifier:len; 40, argument_list; 41, assignment; 42, assignment; 43, assignment; 44, assignment; 45, call; 46, identifier:np; 47, identifier:array; 48, identifier:unique; 49, call; 50, identifier:arr; 51, identifier:current; 52, subscript; 53, identifier:lis; 54, list_comprehension; 55, identifier:arr; 56, list_comprehension; 57, identifier:xi_lis_average; 58, binary_operator:sum(lis) / len(lis); 59, attribute; 60, argument_list; 61, attribute; 62, argument_list; 63, identifier:arr; 64, integer:0; 65, identifier:xi; 66, for_in_clause; 67, if_clause; 68, identifier:xi; 69, for_in_clause; 70, if_clause; 71, call; 72, call; 73, identifier:unique; 74, identifier:append; 75, identifier:xi_lis_average; 76, identifier:arr; 77, identifier:flatten; 78, identifier:xi; 79, identifier:arr; 80, comparison_operator:np.abs(current - xi) < tolerance; 81, identifier:xi; 82, identifier:arr; 83, not_operator; 84, identifier:sum; 85, argument_list; 86, identifier:len; 87, argument_list; 88, call; 89, identifier:tolerance; 90, comparison_operator:np.abs(lis[0] - xi) < tolerance; 91, identifier:lis; 92, identifier:lis; 93, attribute; 94, argument_list; 95, call; 96, identifier:tolerance; 97, identifier:np; 98, identifier:abs; 99, binary_operator:current - xi; 100, attribute; 101, argument_list; 102, identifier:current; 103, identifier:xi; 104, identifier:np; 105, identifier:abs; 106, binary_operator:lis[0] - xi; 107, subscript; 108, identifier:xi; 109, identifier:lis; 110, integer:0
code: def unique(arr, tolerance=1e-6) -> np.ndarray:
      """Return unique elements in 1D array, within tolerance.
  
      Parameters
      ----------
      arr : array_like
          Input array. This will be flattened if it is not already 1D.
      tolerance : number (optional)
          The tolerance for uniqueness.
  
      Returns
      -------
      array
          The sorted unique values.
      """
      arr = sorted(arr.flatten())
      unique = []
      while len(arr) > 0:
          current = arr[0]
          lis = [xi for xi in arr if np.abs(current - xi) < tolerance]
          arr = [xi for xi in arr if not np.abs(lis[0] - xi) < tolerance]
          xi_lis_average = sum(lis) / len(lis)
          unique.append(xi_lis_average)
      return np.array(unique)