Skip to content

Commit f234b97

Browse files
DOC: Added examples to np.lib.stride_tricks.sliding_window_view (numpy#30992)
Co-authored-by: MadPhysicist <jfoxrabinovitz@gmail.com>
1 parent b981a5f commit f234b97

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

numpy/lib/_stride_tricks_impl.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,21 @@ def sliding_window_view(x, window_shape, axis=None, *,
364364
>>> moving_average
365365
array([1., 2., 3., 4.])
366366
367+
To adjust the step size of the sliding window, index the output view along
368+
the desired dimension(s). Using the array shown above:
369+
370+
>>> v[::2]
371+
array([[0, 1, 2],
372+
[2, 3, 4]])
373+
374+
You can slide in the reverse direction using the same technique:
375+
376+
>>> v[::-1]
377+
array([[3, 4, 5],
378+
[2, 3, 4],
379+
[1, 2, 3],
380+
[0, 1, 2]])
381+
367382
The two examples below demonstrate the effect of ``writeable=True``.
368383
369384
Creating a view with the default ``writeable=False`` and then writing to

0 commit comments

Comments
 (0)