code: def write_ndarray_to_tsfile(
      data,
      path,
      problem_name="sample_data",
      class_label=None,
      class_value_list=None,
      equal_length=False,
      series_length=-1,
      missing_values="NaN",
      comment=None,
      fold="",
  ):
      """Output a dataset in ndarray format to .ts file.
  
      Parameters
      ----------
      data: pandas dataframe
          The dataset in a 3d ndarray to be written as a ts file
          which must be of the structure specified in the documentation
          examples/loading_data.ipynb.
          (n_instances, n_columns, n_timepoints)
      path: str
          The full path to output the ts file to.
      problem_name: str, default="sample_data"
          The problemName to print in the header of the ts file and also the name of
          the file.
      class_label: list of str or None, default=None
          The problems class labels to show the possible class values for in the file
          header.
      class_value_list: list, ndarray or None, default=None
          The class values for each case, optional.
      equal_length: bool, default=False
          Indicates whether each series is of equal length.
      series_length: int, default=-1
          Indicates the series length if they are of equal length.
      missing_values: str, default="NaN"
          Representation for missing values.
      comment: str or None, default=None
          Comment text to be inserted before the header in a block.
      fold: str or None, default=None
          Addon at the end of the filename, i.e. _TRAIN or _TEST.
  
      Returns
      -------
      None
  
      Notes
      -----
      This version currently does not support writing timestamp data.
      """
      # ensure data provided is a ndarray
      if not isinstance(data, np.ndarray):
          raise ValueError("Data provided must be a ndarray")
      if class_value_list is not None:
          data, class_value_list = check_X_y(data, class_value_list)
      else:
          data = check_X(data)
      univariate = data.shape[1] == 1
      if class_value_list is not None and class_label is None:
          class_label = np.unique(class_value_list)
      elif class_value_list is None:
          class_value_list = []
      # ensure number of cases is same as the class value list
      if (
          len(data) != len(class_value_list)
          and len(class_value_list) > 0
      ):
          raise IndexError(
              "The number of cases is not the same as the number of given class values"
          )
      if equal_length and series_length == -1:
          raise ValueError(
              "Please specify the series length for equal length time series data."
          )
      if fold is None:
          fold = ""
      file = _write_header(
          path,
          problem_name,
          univariate,
          equal_length,
          series_length,
          class_label,
          fold,
          comment,
      )
      # begin writing the core data for each case
      # which are the series and the class value list if there is any
      for case, value in itertools.zip_longest(data, class_value_list):
          for dimension in case:
              # turn series into comma-separated row
              series = ",".join(
                  [
                      str(num) if not np.isnan(num) else missing_values
                      for num in dimension
                  ]
              )
              file.write(str(series))
              # continue with another dimension for multivariate case
              if not univariate:
                  file.write(":")
          a = ":" if univariate else ""
          if value is not None:
              file.write(f"{a}{value}")  # write the case value if any
          elif class_label is not None:
              file.write(f"{a}{missing_values}")
          file.write("\n")  # open a new line
      file.close()
  
file_path: sktime/sktime/datasets/_readers_writers/ts.py
imports: import itertools
  import numpy
  import pandas
  from sktime.datasets._readers_writers.utils import _alias_mtype_check, _write_header
  from sktime.datatypes import MTYPE_LIST_PANEL, check_is_scitype, convert, convert_to
  from sktime.utils.validation.panel import check_X, check_X_y
label_desc: Use image node_id 4 for calling a global function with example usage: write_ndarray_to_tsfile(data, path, problem_name, class_label, class_value_list, equal_length, series_length, missing_values, comment, fold) without return types