nodes: 0, module; 1, function_definition; 2, function_name:axis_as_object; 3, parameters; 4, block; 5, identifier:arr; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, comment:# make axis to be viewed as a void object as contiguous items; 10, expression_statement; 11, comment:# number of bytes in each void object; 12, expression_statement; 13, comment:# void type with the correct number of bytes; 14, expression_statement; 15, comment:# return the view as such, with the reduced shape; 16, return_statement; 17, identifier:axis; 18, unary_operator; 19, comment:"""cast the given axis of an array to a void object
      if the axis to be cast is contiguous, a view is returned, otherwise a copy is made
      this is useful for efficiently sorting by the content of an axis, for instance
  
      Parameters
      ----------
      arr : ndarray
          array to view as void object type
      axis : int
          axis to view as a void object type
  
      Returns
      -------
      ndarray
          array with the given axis viewed as a void object
      """; 20, assignment; 21, assignment; 22, assignment; 23, assignment; 24, call; 25, integer:1; 26, identifier:shape; 27, attribute; 28, identifier:arr; 29, call; 30, identifier:nbytes; 31, binary_operator:arr.dtype.itemsize * shape[axis]; 32, identifier:voidtype; 33, call; 34, attribute; 35, argument_list; 36, identifier:arr; 37, identifier:shape; 38, attribute; 39, argument_list; 40, attribute; 41, subscript; 42, attribute; 43, argument_list; 44, call; 45, identifier:reshape; 46, call; 47, identifier:np; 48, identifier:ascontiguousarray; 49, call; 50, attribute; 51, identifier:itemsize; 52, identifier:shape; 53, identifier:axis; 54, identifier:np; 55, identifier:dtype; 56, tuple; 57, attribute; 58, argument_list; 59, attribute; 60, argument_list; 61, attribute; 62, argument_list; 63, identifier:arr; 64, identifier:dtype; 65, attribute; 66, identifier:nbytes; 67, identifier:arr; 68, identifier:view; 69, identifier:voidtype; 70, identifier:np; 71, identifier:delete; 72, identifier:shape; 73, identifier:axis; 74, identifier:np; 75, identifier:rollaxis; 76, identifier:arr; 77, identifier:axis; 78, attribute; 79, identifier:np; 80, identifier:void; 81, identifier:arr; 82, identifier:ndim
code: def axis_as_object(arr, axis=-1):
      """cast the given axis of an array to a void object
      if the axis to be cast is contiguous, a view is returned, otherwise a copy is made
      this is useful for efficiently sorting by the content of an axis, for instance
  
      Parameters
      ----------
      arr : ndarray
          array to view as void object type
      axis : int
          axis to view as a void object type
  
      Returns
      -------
      ndarray
          array with the given axis viewed as a void object
      """
      shape = arr.shape
      # make axis to be viewed as a void object as contiguous items
      arr = np.ascontiguousarray(np.rollaxis(arr, axis, arr.ndim))
      # number of bytes in each void object
      nbytes = arr.dtype.itemsize * shape[axis]
      # void type with the correct number of bytes
      voidtype = np.dtype((np.void, nbytes))
      # return the view as such, with the reduced shape
      return arr.view(voidtype).reshape(np.delete(shape, axis))