pflm.utils.flatten_and_sort_data_matrices#

flatten_and_sort_data_matrices(y: list[~numpy.ndarray], t: list[~numpy.ndarray], input_dtype: str | ~numpy.dtype = <class 'numpy.float64'>, w: ~numpy.ndarray | None = None) FlattenFunctionalData[source][source]#

Flatten per-sample 1D arrays into contiguous vectors and build indices.

This function concatenates lists of responses y and times t, expands per-sample weights w to observation level, drops NaNs, and constructs indexing helpers for the observation grid and subject ids.

Parameters:
ylist of np.ndarray

Each element is a 1D array of shape (nt_i,) with responses for sample i.

tlist of np.ndarray

Each element is a 1D array of shape (nt_i,) with time points for sample i.

input_dtypestr or np.dtype, default=np.float64

Target dtype for numeric arrays.

wnp.ndarray, optional

1D array of length len(y) with per-sample weights. If None, uses ones.

Returns:
FlattenFunctionalData

Dataclass holding flattened arrays (y, t, w), grid/subject indices (tid, unique_tid, inverse_tid_idx, sid, unique_sid, sid_cnt).

Raises:
ValueError

If y/t are not lists of 1D arrays with matching lengths, if w is provided but invalid, or if all y values are NaN.

See also

FlattenFunctionalData

The returned dataclass holding the flattened arrays and indices.

Notes

  • NaN entries in y (and matching positions in t) are removed.

  • unique_tid is constructed from the de-duplicated sorted values of t.

  • The tid indices are built via np.digitize against unique_tid.