tslearn.utils.check_dims¶
- tslearn.utils.check_dims(X, X_fit_dims=None, extend=True, check_n_features_only=False)[source]¶
Reshapes X to a 3-dimensional array of X.shape[0] univariate timeseries of length X.shape[1] if X is 2-dimensional and extend is True. Then checks whether the provided X_fit_dims and the dimensions of X (except for the first one), match.
- Parameters:
- Xarray-like
The first array to be compared.
- X_fit_dimstuple (default: None)
The dimensions of the data generated by fit, to compare with the dimensions of the provided array X. If None, then only perform reshaping of X, if necessary.
- extendboolean (default: True)
Whether to reshape X, if it is 2-dimensional.
- check_n_features_only: boolean (default: False)
- Returns:
- array
Reshaped X array
- Raises:
- ValueError
Will raise exception if X is None or (if X_fit_dims is provided) one of the dimensions of the provided data, except the first, does not match X_fit_dims.
Examples
>>> X = numpy.empty((10, 3)) >>> check_dims(X).shape (10, 3, 1) >>> X = numpy.empty((10, 3, 1)) >>> check_dims(X).shape (10, 3, 1) >>> X_fit_dims = (5, 3, 1) >>> check_dims(X, X_fit_dims).shape (10, 3, 1) >>> X_fit_dims = (5, 3, 2) >>> check_dims(X, X_fit_dims) Traceback (most recent call last): ValueError: Dimensions (except first) must match! ((5, 3, 2) and (10, 3, 1) are passed shapes) >>> X_fit_dims = (5, 5, 1) >>> check_dims(X, X_fit_dims, check_n_features_only=True).shape (10, 3, 1) >>> X_fit_dims = (5, 5, 2) >>> check_dims( ... X, ... X_fit_dims, ... check_n_features_only=True ... ) Traceback (most recent call last): ValueError: Number of features of the provided timeseries must match! (last dimension) must match the one of the fitted data! ((5, 5, 2) and (10, 3, 1) are passed shapes)