MCPcopy Index your code
hub / github.com/numpy/numpy / sliding_window_view

Function sliding_window_view

numpy/lib/_stride_tricks_impl.py:180–444  ·  view source on GitHub ↗

Create a sliding window view into the array with the given window shape. Also known as rolling or moving window, the window slides across all dimensions of the array and extracts subsets of the array at all window positions. .. versionadded:: 1.20.0 Parameters -------

(x, window_shape, axis=None, *,
                        subok=False, writeable=False)

Source from the content-addressed store, hash-verified

178 _sliding_window_view_dispatcher, module="numpy.lib.stride_tricks"
179)
180def sliding_window_view(x, window_shape, axis=None, *,
181 subok=False, writeable=False):
182 """
183 Create a sliding window view into the array with the given window shape.
184
185 Also known as rolling or moving window, the window slides across all
186 dimensions of the array and extracts subsets of the array at all window
187 positions.
188
189 .. versionadded:: 1.20.0
190
191 Parameters
192 ----------
193 x : array_like
194 Array to create the sliding window view from.
195 window_shape : int or tuple of int
196 Size of window over each axis that takes part in the sliding window.
197 If `axis` is not present, must have same length as the number of input
198 array dimensions. Single integers `i` are treated as if they were the
199 tuple `(i,)`.
200 axis : int or tuple of int, optional
201 Axis or axes along which the sliding window is applied.
202 By default, the sliding window is applied to all axes and
203 `window_shape[i]` will refer to axis `i` of `x`.
204 If `axis` is given as a `tuple of int`, `window_shape[i]` will refer to
205 the axis `axis[i]` of `x`.
206 Single integers `i` are treated as if they were the tuple `(i,)`.
207 subok : bool, optional
208 If True, sub-classes will be passed-through, otherwise the returned
209 array will be forced to be a base-class array (default).
210 writeable : bool, optional
211 When true, allow writing to the returned view. The default is false,
212 as this should be used with caution: the returned view contains the
213 same memory location multiple times, so writing to one location will
214 cause others to change.
215
216 Returns
217 -------
218 view : ndarray
219 Sliding window view of the array. The sliding window dimensions are
220 inserted at the end, and the original dimensions are trimmed as
221 required by the size of the sliding window.
222 That is, ``view.shape = x_shape_trimmed + window_shape``, where
223 ``x_shape_trimmed`` is ``x.shape`` with every entry reduced by one less
224 than the corresponding window size.
225
226 See Also
227 --------
228 lib.stride_tricks.as_strided: A lower-level and less safe routine for
229 creating arbitrary views from custom shape and strides. Use the
230 ``check_bounds`` parameter for bounds validation.
231 broadcast_to: broadcast an array to a given shape.
232
233 Notes
234 -----
235 .. warning::
236
237 This function creates views with overlapping memory. When

Callers 8

test_1dMethod · 0.90
test_2dMethod · 0.90
test_2d_with_axisMethod · 0.90
test_2d_repeated_axisMethod · 0.90
test_2d_without_axisMethod · 0.90
test_errorsMethod · 0.90
test_writeableMethod · 0.90
test_subokMethod · 0.90

Calls 3

normalize_axis_tupleFunction · 0.90
as_stridedFunction · 0.85
anyMethod · 0.45

Tested by 8

test_1dMethod · 0.72
test_2dMethod · 0.72
test_2d_with_axisMethod · 0.72
test_2d_repeated_axisMethod · 0.72
test_2d_without_axisMethod · 0.72
test_errorsMethod · 0.72
test_writeableMethod · 0.72
test_subokMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…