sliding_window¶
- sliding_window(x_data: ndarray, labels: ndarray, scorer: callable, window_size: int = 20, axis: int = -1, n_jobs: int = -3, **kwargs) ndarray[source][source]¶
Compute a function over a sliding window.
- Parameters:
x_data (
np.ndarray,shape (...,trials,time)) – The data to compute the function overlabels (
np.ndarray,shape (trials,)) – The labels for each trialscorer (
callable) – The function to compute over the sliding window. Must take two arguments, the data and the labels.window_size (
int) – The size of the sliding windowaxis (
int) – The axis to compute the sliding window overn_jobs (
int) – The number of jobs to run in parallel
- Returns:
The output of the function, shape (…, time - window_size + 1)
- Return type:
np.ndarray
Examples
>>> def square(x, labels): ... return np.mean(x ** 2, where=labels == 1) >>> x_data = np.arange(40).reshape(4, 10) >>> labels = np.array([0, 1, 1]) >>> sliding_window(x_data, labels, square, window_size=3) array([397.5, 431.5, 467.5, 505.5, 545.5, 587.5, 631.5])