code: def piecewise_normal(
      means: npt.ArrayLike,
      lengths: npt.ArrayLike,
      std_dev: Union[npt.ArrayLike, float] = 1.0,
      random_state: Union[int, np.random.RandomState] = None,
  ) -> npt.ArrayLike:
      """Generate series from segments.
  
      Each segment has length specified in ``lengths`` and data sampled from a normal
      distribution with a mean from ``means`` and standard deviation from ``std_dev``.
  
      Parameters
      ----------
      means : array_like
          Means of the segments to be generated
      lengths : array_like
          Lengths of the segments to be generated
      std_dev : float or array_like
          Standard deviations of the segments to be generated
      random_state : int or np.random.RandomState
          Either a random seed or RandomState instance
  
      Returns
      -------
      data : np.array
          univariate time series as np.array
  
      Examples
      --------
      >>> from sktime.annotation.datagen import piecewise_normal
      >>> piecewise_normal([1, 2, 3], lengths=[2, 4, 8], random_state=42) # doctest: +SKIP
      array([1.49671415, 0.8617357 , 2.64768854, 3.52302986, 1.76584663,
          1.76586304, 4.57921282, 3.76743473, 2.53052561, 3.54256004,
          2.53658231, 2.53427025, 3.24196227, 1.08671976])
  
      >>> from sktime.annotation.datagen import piecewise_normal
      >>> piecewise_normal([1, 2, 3], lengths=[2, 4, 8], std_dev=0) # doctest: +SKIP
      array([1., 1., 2., 2., 2., 2., 3., 3., 3., 3., 3., 3., 3., 3.])
  
      >>> from sktime.annotation.datagen import piecewise_normal
      >>> piecewise_normal([1, 2, 3], lengths=[2, 4, 8], std_dev=[0, 0.5, 1.0])\
          # doctest: +SKIP
      array([1.        , 1.        , 2.32384427, 2.76151493, 1.88292331,
          1.88293152, 4.57921282, 3.76743473, 2.53052561, 3.54256004,
          2.53658231, 2.53427025, 3.24196227, 1.08671976])
      """
      rng = check_random_state(random_state)
      assert len(means) == len(lengths)
  
      if isinstance(std_dev, (float, int)):
          std_dev = np.repeat(std_dev, len(means))
  
      assert len(std_dev) == len(means)
  
      segments_data = [
          rng.normal(loc=mean, scale=sd, size=[length])
          for mean, length, sd in zip(means, lengths, std_dev)
      ]
      return np.concatenate(tuple(segments_data))
  
file_path: sktime/sktime/annotation/datagen.py
imports: from typing import Union
  import numpy
  import numpy.typing
  from sklearn.utils.validation import check_random_state
label_desc: Use image node_id 2 for calling a global function with example usage: piecewise_normal(means, lengths, std_dev, random_state) and returns: np