pymovements.transforms.cut_into_subsequences
- pymovements.transforms.cut_into_subsequences(arr: ndarray, window_size: int, keep_padded: bool = True) ndarray[source]
Cut sequence into subsequences of equal length.
- Parameters:
arr (np.ndarray) – Input sequence of shape (N, L, C).
window_size (int) – size of subsequences
keep_padded (bool) – If True, last subsequence (if not of length window_size) is kept in the output array and padded with np.nan.
- Returns:
Output sequence with new window length of shape (N’, L’, C)
- Return type:
np.ndarray
Examples
We first create an array with 2 channels and a sequence length of 13.
>>> arr = np.ones((1, 13, 2)) >>> arr.shape (1, 13, 2)
We now cut the original array into three subsequences of length 5.
>>> arr_cut = cut_into_subsequences( ... arr=arr, ... window_size=5, ... keep_padded=True, ... ) >>> arr_cut.shape (3, 5, 2)
The last subsequence is padded with nan to have a length of 5.
>>> arr_cut[-1] array([[ 1., 1.], [ 1., 1.], [ 1., 1.], [nan, nan], [nan, nan]])
We can also drop any remaining sequences that would need padding by passing
keep_padded=False.>>> arr_cut = cut_into_subsequences( ... arr=arr, ... window_size=5, ... keep_padded=False, ... ) >>> arr_cut.shape (2, 5, 2)