code: def _extract_lagged_vals_from_windows(
      windows: np.ndarray,
      lags_to_extract: Optional[
          Union[np.ndarray, List[np.ndarray]]
      ] = None,
  ) -> np.ndarray:
      """
      Helper function called by `_create_lagged_data_by_moving_window` that
      reshapes the `windows` formed by `strided_moving_window` from the
      shape `(num_windows, num_components, num_series, window_len)` to the
      shape `(num_windows, num_components * window_len, num_series)`. This reshaping
      is done such that the order of elements along axis 1 matches the pattern
      described in the docstring of `create_lagged_data`.
  
      If `lags_to_extract` is not specified, all of the values within each window is extracted.
      If `lags_to_extract` is specified as an np.ndarray, then only those values within each window that
      are indexed by `lags_to_extract` will be returned. In such cases, the shape of the returned
      lagged values is `(num_windows, num_components * lags_to_extract.size, num_series)`. For example,
      if `lags_to_extract = [-2]`, only the second-to-last values within each window will be extracted.
      If `lags_to_extract` is specified as a list of np.ndarray, the values will be extracted using the
      lags provided for each component. In such cases, the shape of the returned lagged values is
      `(num_windows, sum([comp_lags.size for comp_lags in lags_to_extract]), num_series)`. For example,
      if `lags_to_extract = [[-2, -1], [-1]]`, the second-to-last and last values of the first component
      and the last values of the second component within each window will be extracted.
      """
      # windows.shape = (num_windows, num_components, num_samples, window_len):
      if isinstance(lags_to_extract, list):
          # iterate over the components-specific lags
          comp_windows = [
              windows[:, i, :, comp_lags_to_extract]
              for i, comp_lags_to_extract in enumerate(lags_to_extract)
          ]
          # windows.shape = (sum(lags_len) across components, num_windows, num_samples):
          windows = np.concatenate(comp_windows, axis=0)
          lagged_vals = np.moveaxis(windows, (1, 0, 2), (0, 1, 2))
      else:
          if lags_to_extract is not None:
              windows = windows[:, :, :, lags_to_extract]
          # windows.shape = (num_windows, window_len, num_components, num_samples):
          windows = np.moveaxis(windows, (0, 3, 1, 2), (0, 1, 2, 3))
          # lagged_vals.shape = (num_windows, num_components*window_len, num_samples):
          lagged_vals = windows.reshape(
              (windows.shape[0], -1, windows.shape[-1])
          )
      return lagged_vals
  
imports: import warnings
  from functools import reduce
  from math import inf
  from typing import Dict, List, Optional, Sequence, Tuple, Union
  from itertools import chain
  import numpy
  import pandas
  from numpy.lib.stride_tricks import as_strided
  from darts.logging import get_logger, raise_if, raise_if_not, raise_log
  from darts.timeseries import TimeSeries
  from darts.utils.utils import get_single_series, series2seq
label_desc: Use image node_id 7 for calling a global function with example usage: _extract_lagged_vals_from_windows(windows, lags_to_extract) and returns: lagged_vals