nmrglue.analysis.analysisbase.ndwindow

class nmrglue.analysis.analysisbase.ndwindow(shape, wsize)[source]

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

Size of array to generate tuples of slices from.

wsize : tuple of ints

Window/sub-array size. Size of the area to select from array. This is the maximum size of the window.

See also

ndwindow_index
Iterator of a ndwindow and index of the window center
ndwindow_inside
Iterator over equal sized windows in the array.

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]]
[[ 1  2  3]
 [ 5  6  7]
 [ 9 10 11]]
[[ 2  3]
 [ 6  7]
 [10 11]]
[[4 5]
 [8 9]]
[[ 4  5  6]
 [ 8  9 10]]
[[ 5  6  7]
 [ 9 10 11]]
[[ 6  7]
 [10 11]]
__init__(shape, wsize)[source]

Set up the ndwindow object

Methods

__init__(shape, wsize) Set up the ndwindow object
next(() -> the next value, ...)

Previous topic

nmrglue.analysis.analysisbase.squish

Next topic

nmrglue.analysis.analysisbase.ndwindow_index

This Page