Utilities¶
- confetti.utils.array_to_string(arr: ndarray) str¶
Convert a NumPy array into a single-line space-separated string.
Useful for serializing arrays into CSV files where nested structures are not supported.
- Parameters:
arr (ndarray) – The array to be flattened and serialized.
- Returns:
A flattened, space-separated representation of the array.
- Return type:
str
- confetti.utils.convert_string_to_array(data_string: str, timesteps: int, channels: int) ndarray¶
Convert a serialized array string into a 2D NumPy array.
This function reconstructs a flattened, space-separated string representation of an array into a 2D array of shape
(timesteps, channels). Brackets and line breaks are removed automatically.- Parameters:
data_string (str) – The flattened array stored as a whitespace-separated string.
timesteps (int) – Number of expected time steps in the reconstructed array.
channels (int) – Number of expected channels in the reconstructed array.
- Returns:
The reconstructed numeric array.
- Return type:
ndarray of shape (timesteps, channels)
- Raises:
CONFETTIConfigurationError – If the number of parsed elements does not match
timesteps * channels.
- confetti.utils.load_multivariate_ts_from_csv(file_path: str | Path) Tuple[ndarray, ndarray]¶
Load a multivariate time-series dataset saved with
save_multivariate_ts_as_csv.This function reconstructs the original
Xarray by reshaping the long-format CSV and retrieves the sample-level labels from the companion*_labels.csvfile.- Parameters:
file_path (str or Path) – Path to the main feature CSV file.
- Returns:
X (ndarray of shape (n_samples, n_time_steps, n_features)) – The reconstructed multivariate time series.
y (ndarray of shape (n_samples,)) – The label associated with each sample.
Note
The function expects two files in the same directory:
<file>.csv<file>_labels.csv
- confetti.utils.save_multivariate_ts_as_csv(file_path: str | Path, x: ndarray, y: ndarray) None¶
Save a multivariate time-series dataset to CSV in long format.
The time-series array
xis converted into a long-format table where each row corresponds to one sample–time-step pair. The function also writes a companion*_labels.csvfile storing a single label per sample.- Parameters:
file_path (str or Path) – Destination path for the main CSV file.
x (ndarray of shape (n_samples, n_time_steps, n_features)) – The multivariate time series data.
y (ndarray of shape (n_samples,)) – The label associated with each sample.
Note
Two files are written:
<file>.csv: long-format feature table<file>_labels.csv: labels indexed bysample_id