Skip to content

Commit 2a4ff93

Browse files
authored
Merge pull request #492 from pynapple-org/fix_perievent
Fixing perievent
2 parents 6751c8b + df16878 commit 2a4ff93

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

pynapple/process/_process_functions.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,13 @@ def _perievent_continuous(
246246

247247
w_sizes = slice_idx[:, 1] - slice_idx[:, 0] # Different sizes
248248

249-
all_w_sizes = np.unique(w_sizes)
250-
all_w_start = np.unique(w_starts)
251-
252-
for w_size in all_w_sizes:
253-
for w_start in all_w_start:
254-
col_idx = w_sizes == w_size
255-
new_idx = np.zeros((w_size, np.sum(col_idx)), dtype=int)
256-
for i, tmp in enumerate(slice_idx[col_idx]):
257-
new_idx[:, i] = np.arange(tmp[0], tmp[1])
258-
259-
new_data_array[w_start : w_start + w_size, col_idx] = data_array[
260-
new_idx
261-
]
249+
unique_pairs = np.unique(np.column_stack([w_sizes, w_starts]), axis=0)
250+
for w_size, w_start in unique_pairs:
251+
col_idx = (w_sizes == w_size) & (w_starts == w_start)
252+
new_idx = np.zeros((w_size, np.sum(col_idx)), dtype=int)
253+
for i, slc in enumerate(slice_idx[col_idx]):
254+
new_idx[:, i] = np.arange(slc[0], slc[1])
255+
256+
new_data_array[w_start : w_start + w_size, col_idx] = data_array[new_idx]
262257

263258
return new_data_array

0 commit comments

Comments
 (0)