An N-dimensional iterator to slice arrays into windows.
Given the shape of an array and a window size, an ‘ndwindow’ instance iterators over tuples of slices which slice an the array into wsize sub-arrays. At each iteration, the index of the center of the sub-array is incremented by one along the last dimension. Array borders are ignored so the resulting sub-array can be smaller than wsize. If wsize contains even values the window is off center containing an additional point with lower index.
Parameters : | size : tuple of ints
wsize : tuple of ints
|
---|
See also
Examples
>>> a = np.arange(12).reshape(3,4)
>>> for s in ndwindow(a.shape,(3,3))
... print a[s]
[[0 1]
[4 5]]
[[0 1 2]
[4 5 6]]
[[1 2 3]
[5 6 7]]
[[2 3]
[6 7]]
[[0 1]
[4 5]
[8 9]]
[[ 0 1 2]
[ 4 5 6]
[ 8 9 10]]
...
Methods
__init__(shape, wsize) | Set up the ndwindow object |
next(() -> the next value, ...) |