pyeeg.utils.shift_array

pyeeg.utils.shift_array(arr, win=2, overlap=0, padding=False, axis=0)

Returns segments of an array (overlapping moving windows) using the as_strided function from NumPy.

Parameters:
  • arr (numpy.ndarray)

  • win (int) – Number of samples in one window

  • overlap (int) – Number of samples overlapping (0 means no overlap)

  • pad (function) – padding function to be applied to data (if False will throw away data)

  • axis (int) – Axis on which to apply the rolling window

Returns:

shiftarr – Shifted copies of array segments

Return type:

ndarray

Notes

Using the as_strided function trick from Numpy means the returned array share the same memory buffer as the original array, so use with caution! Maybe .copy() the result if needed. This is the way for 2d array with overlap (i.e. step size != 1, which was the easy way):

as_strided(a, (num_windows, win_size, n_features), (size_onelement * hop_size * n_feats, original_strides))