code: def time_series_to_str(ts, fmt="%.18e"):
      """Transforms a time series to its representation as a string (used when
      saving time series to disk).
  
      Parameters
      ----------
      ts : array-like
          Time series to be represented.
      fmt : string (default: "%.18e")
          Format to be used to write each value (only ASCII characters).
  
      Returns
      -------
      string
          String representation of the time-series.
  
      Examples
      --------
      >>> time_series_to_str([1, 2, 3, 4], fmt="%.1f")
      '1.0 2.0 3.0 4.0'
      >>> time_series_to_str([[1, 3], [2, 4]], fmt="%.1f")
      '1.0 2.0|3.0 4.0'
  
      See Also
      --------
      load_time_series_txt : Load time series from disk
      str_to_time_series : Transform a string into a time series
      """
      ts_ = to_time_series(ts)
      out = StringIO()
      numpy.savetxt(
          out,
          ts_.T,
          fmt=fmt,
          delimiter=" ",
          newline="|",
          encoding="bytes",
      )
      return out.getvalue()[:-1]
  
imports: import warnings
  from io import StringIO
  import numpy
  from sklearn.base import TransformerMixin
  from sklearn.utils import column_or_1d
  from sklearn.utils.validation import check_is_fitted
  from tslearn.backend import instantiate_backend
  from tslearn.bases import TimeSeriesBaseEstimator
label_desc: Use image node_id 4 for calling a global function with example usage: time_series_to_str(ts, fmt) and returns: out