nodes: 0, module; 1, function_definition; 2, function_name:knt2mlt; 3, parameters; 4, block; 5, identifier:t; 6, expression_statement; 7, expression_statement; 8, if_statement; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, return_statement; 13, comment:"""Count multiplicities of elements in a sorted list or rank-1 array.
  
  Minimal emulation of MATLAB's ``knt2mlt``.
  
  Parameters:
      t:
          Python list or rank-1 array. Must be sorted!
  
  Returns:
      out
          rank-1 array such that
          out[k] = #{ t[i] == t[k] for i < k }
  
  Example:
      If ``t = [1, 1, 2, 3, 3, 3]``, then ``out = [0, 1, 0, 0, 1, 2]``.
  
  Caveat:
      Requires input to be already sorted (this is not checked).
  """; 14, assignment; 15, comparison_operator:t.ndim > 1; 16, block; 17, assignment; 18, assignment; 19, identifier:k; 20, call; 21, block; 22, call; 23, identifier:t; 24, call; 25, attribute; 26, integer:1; 27, raise_statement; 28, identifier:out; 29, list; 30, identifier:e; 31, None; 32, identifier:range; 33, argument_list; 34, if_statement; 35, expression_statement; 36, attribute; 37, argument_list; 38, attribute; 39, argument_list; 40, identifier:t; 41, identifier:ndim; 42, call; 43, subscript; 44, comparison_operator:t[k] != e; 45, block; 46, else_clause; 47, call; 48, identifier:np; 49, identifier:array; 50, identifier:out; 51, identifier:np; 52, identifier:atleast_1d; 53, identifier:t; 54, identifier:ValueError; 55, argument_list; 56, attribute; 57, integer:0; 58, subscript; 59, identifier:e; 60, expression_statement; 61, expression_statement; 62, block; 63, attribute; 64, argument_list; 65, string:"t must be a list or a rank-1 array"; 66, identifier:t; 67, identifier:shape; 68, identifier:t; 69, identifier:k; 70, assignment; 71, assignment; 72, expression_statement; 73, identifier:out; 74, identifier:append; 75, identifier:count; 76, identifier:e; 77, subscript; 78, identifier:count; 79, integer:0; 80, augmented_assignment; 81, identifier:t; 82, identifier:k; 83, identifier:count; 84, integer:1
code: def knt2mlt(t):
      """Count multiplicities of elements in a sorted list or rank-1 array.
  
  Minimal emulation of MATLAB's ``knt2mlt``.
  
  Parameters:
      t:
          Python list or rank-1 array. Must be sorted!
  
  Returns:
      out
          rank-1 array such that
          out[k] = #{ t[i] == t[k] for i < k }
  
  Example:
      If ``t = [1, 1, 2, 3, 3, 3]``, then ``out = [0, 1, 0, 0, 1, 2]``.
  
  Caveat:
      Requires input to be already sorted (this is not checked).
  """
      t = np.atleast_1d(t)
      if t.ndim > 1:
          raise ValueError("t must be a list or a rank-1 array")
  
      out   = []
      e     = None
      for k in range(t.shape[0]):
          if t[k] != e:
              e     = t[k]
              count = 0
          else:
              count += 1
          out.append(count)
  
      return np.array( out )