code: def _series_to_segments(time_series, segment_size):
      """Transforms a time series (or a set of time series) into an array of its
      segments of length segment_size.
  
      Examples
      --------
      >>> from tslearn.utils import to_time_series
      >>> time_series = to_time_series([1, 2, 3, 4, 5])
      >>> segments = _series_to_segments(time_series, segment_size=2)
      >>> segments.shape
      (4, 2, 1)
      >>> segments[:, :, 0]
      array([[1., 2.],
             [2., 3.],
             [3., 4.],
             [4., 5.]])
      >>> from tslearn.utils import to_time_series_dataset
      >>> dataset = to_time_series_dataset([time_series])
      >>> dataset.shape
      (1, 5, 1)
      >>> segments = _series_to_segments(dataset, segment_size=2)
      >>> segments.shape
      (4, 2, 1)
      >>> segments[:, :, 0]
      array([[1., 2.],
             [2., 3.],
             [3., 4.],
             [4., 5.]])
      """
      if time_series.ndim == 3:
          l_segments = [
              _series_to_segments(ts, segment_size)
              for ts in time_series
          ]
          return np.vstack(l_segments)
      elem_size = time_series.strides[0]
      segments = as_strided(
          time_series,
          strides=(elem_size, elem_size, time_series.strides[1]),
          shape=(
              time_series.shape[0] - segment_size + 1,
              segment_size,
              time_series.shape[1],
          ),
          writeable=False,
      )
      return segments
  
imports: import numpy
  from numpy.lib.stride_tricks import as_strided
  from scipy.spatial.distance import pdist, squareform
  from sklearn.base import TransformerMixin
  from sklearn.utils.validation import check_array, check_is_fitted
  from tslearn.bases import BaseModelPackage, TimeSeriesBaseEstimator
  from tslearn.preprocessing import TimeSeriesScalerMeanVariance
  from tslearn.utils import check_dims
label_desc: Use image node_id 1 for calling a global function with example usage: _series_to_segments(time_series, segment_size) and returns: segments, np