pymovements.gaze.transforms_numpy.split#
- pymovements.gaze.transforms_numpy.split(arr: ndarray, window_size: int, keep_padded: bool = True) ndarray #
Split 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. (default: True)
- Returns:
Array of split sequences 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 split the original array into three subsequences of length 5.
>>> arr_split = split( ... arr=arr, ... window_size=5, ... keep_padded=True, ... ) >>> arr_split.shape (3, 5, 2)
The last subsequence is padded with nan to have a length of 5.
>>> arr_split[-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_split = split( ... arr=arr, ... window_size=5, ... keep_padded=False, ... ) >>> arr_split.shape (2, 5, 2)