code: def _right_squeeze(arr, stop_dim=0):
      """
      Remove trailing singleton dimensions
  
      Parameters
      ----------
      arr : ndarray
          Input array
      stop_dim : int
          Dimension where checking should stop so that shape[i] is not checked
          for i < stop_dim
  
      Returns
      -------
      squeezed : ndarray
          Array with all trailing singleton dimensions (0 or 1) removed.
          Singleton dimensions for dimension < stop_dim are retained.
      """
      last = arr.ndim
      for s in reversed(arr.shape):
          if s > 1:
              break
          last -= 1
      last = max(last, stop_dim)
  
      return arr.reshape(arr.shape[:last])
  
file_path: statsmodels/statsmodels/tools/validation/validation.py
imports: from typing import Any, Optional
  from collections.abc import Mapping
  import numpy
  import pandas
label_desc: Use image node_id 1 for calling a global function with example usage: _right_squeeze(arr, stop_dim) and returns: arr