code: def piecewise_normal_multivariate(
      means: npt.ArrayLike,
      lengths: npt.ArrayLike,
      variances: Union[npt.ArrayLike, float] = 1.0,
      covariances: npt.ArrayLike = None,
      random_state: Union[int, np.random.RandomState] = None,
  ) -> npt.ArrayLike:
      """Generate multivariate series from segments.
  
      Each segment has length specified in ``lengths`` and data sampled from a
      multivariate normal distribution with a mean from ``means`` and covariance
      from ``covariances`` (either specified or built from ``variances`` when
      unspecified)
  
      Parameters
      ----------
      lengths : array_like
          Lengths of the segments to be generated of shape (n_segments,)
      means : array_like
          Means of the segments to be generated, as an array of shape
          (n_segments, n_series)
      variances : float or array_like (default=1.0)
          Variance of the segments to be generated
      covariances : array_like (default=None)
          Covariances of segments to be generated of shape
          (n_segments, n_series, n_series)
          If None, this will be constructed from variances by assuming independence
          of random variables, i.e. variance as diagonal elements of covariance matrix
      random_state : int or np.random.RandomState
          Either a random seed or ``RandomState`` instance
  
      Returns
      -------
      data : array_like
          Multivariate time series as ``np.array`` of shape (sum(lengths), n_series)
  
      Examples
      --------
      >>> from sktime.annotation.datagen import piecewise_normal_multivariate
      >>> piecewise_normal_multivariate(means=[[1, 1], [2, 2], [3, 3]],\
          lengths=[2, 3, 1], random_state=2)
      array([[ 0.58324215,  0.94373317],
             [-1.1361961 ,  2.64027081],
             [ 0.20656441,  1.15825263],
             [ 2.50288142,  0.75471191],
             [ 0.94204778,  1.09099239],
             [ 3.55145404,  5.29220801]])
  
      >>> from sktime.annotation.datagen import piecewise_normal_multivariate
      >>> piecewise_normal_multivariate(means=[[1, 1], [2, 2], [3, 3]],\
          lengths=[2, 3, 1], variances=[[1.0, 1.0], [1.0, 1.0], [1.0, 1.0]],\
          random_state=2)
      array([[ 0.58324215,  0.94373317],
             [-1.1361961 ,  2.64027081],
             [ 0.20656441,  1.15825263],
             [ 2.50288142,  0.75471191],
             [ 0.94204778,  1.09099239],
             [ 3.55145404,  5.29220801]])
  
      >>> from sktime.annotation.datagen import piecewise_normal_multivariate
      >>> piecewise_normal_multivariate(means=[[1, 1], [2, 2], [3, 3]],\
          lengths=[2, 3, 1], covariances=[[[1.0, 0], [0, 1.0]], [[1.0, 0],\
              [0, 1.0]], [[1.0, 0], [0, 1.0]]], random_state=2)
      array([[ 0.58324215,  0.94373317],
             [-1.1361961 ,  2.64027081],
             [ 0.20656441,  1.15825263],
             [ 2.50288142,  0.75471191],
             [ 0.94204778,  1.09099239],
             [ 3.55145404,  5.29220801]])
  
      >>> from sktime.annotation.datagen import piecewise_normal_multivariate
      >>> piecewise_normal_multivariate(means=[[1, 3], [4, 5]], lengths=[3, 3],\
          covariances=[[[0.5, 0.3], [0.3, 1.0]], [[1.0, 0.3], [0.3, 0.7]]],\
          random_state=2)
      array([[ 0.78066776,  2.61125356],
             [ 0.92296736,  0.51689669],
             [-0.2694238 ,  1.47959507],
             [ 4.00389069,  3.95225998],
             [ 5.32264874,  5.05088075],
             [ 2.62479901,  6.08308546]])
      """
  
      def get_covariances(var):
          """Fill 1D variance array of length N to 2D covariance array of size (N,N)."""
          cov = np.zeros((N, N), float)
          np.fill_diagonal(cov, var)
          return cov
  
      L, N = np.array(means).shape
  
      rng = check_random_state(random_state)
      assert len(lengths) == L
  
      # if no covariance is specified, build it from variance
      # assuming independent random variables
      if covariances is None:
          assert variances is not None
  
          # variances van be specified as a float, make 1D array, repeat L times
          if isinstance(variances, (float, int)):
              variances = np.repeat(variances, N)
              variances = np.tile(variances, (L, 1))
  
          assert np.array(variances).shape == (L, N)
  
          # get covariance matrices from variance arrays
          covariances = [get_covariances(var) for var in variances]
  
      else:
          assert all(
              np.allclose(np.array(cov), np.array(cov).T)
              for cov in covariances
          )
          assert all(
              np.all(np.linalg.eigvals(cov) >= 0) for cov in covariances
          )
  
      assert np.array(covariances).shape[0] == L
      assert np.array(covariances).shape[1] == N
  
      return np.concatenate(
          [
              rng.multivariate_normal(mean=mean, cov=cov, size=length)
              for mean, cov, length in zip(means, covariances, lengths)
          ]
      )
  
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 1 for calling a global function with example usage: piecewise_normal_multivariate(means, lengths, variances, covariances, random_state) and returns: np, cov