code: def from_nested_to_2d_array(X, return_numpy=False):
      """Convert nested Panel to 2D numpy Panel.
  
      Convert nested pandas DataFrame or Series with NumPy arrays or
      pandas Series in cells into tabular
      pandas DataFrame with primitives in cells, i.e. a data frame with the
      same number of rows as the input data and
      as many columns as there are observations in the nested series. Requires
      series to be have the same index.
  
      Parameters
      ----------
      X : nested pd.DataFrame or nested pd.Series
      return_numpy : bool, default = False
          - If True, returns a NumPy array of the tabular data.
          - If False, returns a pandas DataFrame with row and column names.
  
      Returns
      -------
       Xt : pandas DataFrame
          Transformed DataFrame in tabular format
      """
      # TODO does not handle dataframes with nested series columns *and*
      #  standard columns containing only primitives
  
      # convert nested data into tabular data
      if isinstance(X, pd.Series):
          Xt = np.array(X.tolist())
  
      elif isinstance(X, pd.DataFrame):
          try:
              Xt = np.hstack(
                  [X.iloc[:, i].tolist() for i in range(X.shape[1])]
              )
  
          # except strange key error for specific case
          except KeyError:
              if (X.shape == (1, 1)) and (X.iloc[0, 0].shape == (1,)):
                  # in fact only breaks when an additional condition is met,
                  # namely that the index of the time series of a single value
                  # does not start with 0, e.g. pd.RangeIndex(9, 10) as is the
                  # case in forecasting
                  Xt = X.iloc[0, 0].values
              else:
                  raise
  
          if Xt.ndim != 2:
              raise ValueError(
                  "Tabularization failed, it's possible that not "
                  "all series were of equal length"
              )
  
      else:
          raise ValueError(
              f"Expected input is pandas Series or pandas DataFrame, "
              f"but found: {type(X)}"
          )
  
      if return_numpy:
          return Xt
  
      Xt = pd.DataFrame(Xt)
  
      # create column names from time index
      if X.ndim == 1:
          time_index = (
              X.iloc[0].index
              if hasattr(X.iloc[0], "index")
              else np.arange(X.iloc[0].shape[0])
          )
          columns = [f"{X.name}__{i}" for i in time_index]
  
      else:
          columns = []
          for colname, col in X.items():
              time_index = (
                  col.iloc[0].index
                  if hasattr(col.iloc[0], "index")
                  else np.arange(col.iloc[0].shape[0])
              )
              columns.extend([f"{colname}__{i}" for i in time_index])
  
      Xt.index = X.index
      Xt.columns = columns
      return Xt
  
imports: import numpy
  import pandas
  from sktime.datatypes._convert_utils._coerce import _coerce_df_dtypes
  from sktime.datatypes._convert_utils._convert import _extend_conversions
  from sktime.datatypes._panel._registry import MTYPE_LIST_PANEL
  from sktime.utils.pandas import df_map
  from sktime.utils.validation._dependencies import _check_soft_dependencies
label_desc: Use image node_id 10 for calling a global function with example usage: from_nested_to_2d_array(X, return_numpy) and returns: Xt, Xt