tslearn.utils.to_time_series(ts, remove_nans=False, be=None)[source]

Transforms a time series so that it fits the format used in tslearn models.

tsarray-like, shape=(sz, d) or (sz,)

The time series to be transformed. If shape is (sz,), the time series is assumed to be univariate.

remove_nansbool (default: False)

Whether trailing NaNs at the end of the time series should be removed or not

beBackend object or string or None

Backend. If be is an instance of the class NumPyBackend or the string “numpy”, the NumPy backend is used. If be is an instance of the class PyTorchBackend or the string “pytorch”, the PyTorch backend is used. If be is None, the backend is determined by the input arrays. See our dedicated user-guide page for more information.

ts_outarray-like, shape=(sz, d)

The transformed time series. This is always guaraneteed to be a new time series and never just a view into the old one.

See also


Transforms a dataset of time series


>>> to_time_series([1, 2])
>>> to_time_series([1, 2, numpy.nan])
array([[ 1.],
       [ 2.],
>>> to_time_series([1, 2, numpy.nan], remove_nans=True)