code: def to_np_array(
      ts: Union["tsFrame", np.ndarray],
      target_vars: Union[List[str], List[int]] = None,
  ):
      if target_vars is None:
          if isinstance(ts, np.ndarray):
              if len(ts.shape) == 1:
                  ts = ts.reshape(-1, 1)
          target_vars = np.arange(ts.shape[1]).tolist()
  
      if len(ts.shape) != 2:
          raise RuntimeError(
              f"Error: expects data with 2 dimensions received {len(ts.shape)}"
          )
  
      if isinstance(ts, pd.DataFrame):
          target_vars = [
              ts.columns[tgt] if isinstance(tgt, int) else tgt
              for tgt in target_vars
          ]
          assert (
              all([tgt in ts for tgt in target_vars])
              and len(target_vars) > 0
          ), "Error: improper variable specification!"
          ts_array = ts[target_vars].values
      else:
          ts_array = ts[:, target_vars]
      return ts_array
  
imports: from typing import List, Union
  import numpy
  import pandas
label_desc: Use image node_id 2 for calling a global function with example usage: to_np_array(ts, target_vars) and returns: ts_array