I'd recommend using sliding_window_view. Change:
nStencil = 3
x_neighbours = (
x[indexStart:indexStop]
for indexStart, indexStop in zip(
(None, *range(1,nStencil)),
(*range(1-nStencil,0), None),
)
)
To:
nStencil = 3
sliding_view = sliding_window_view(x, nStencil)
x_neighbours = tuple(sliding_view[:, i] for i in range(nStencil))