{ } Raw JSON

bundles / skimage latest / skimage / util / shape / view_as_windows

function

skimage.util.shape:view_as_windows

source: /dev/scikit-image/src/skimage/util/shape.py :96

Signature

def   view_as_windows ( arr_in window_shape step = 1 )

Summary

Rolling window view of the input n-dimensional array.

Extended Summary

Windows are overlapping views of the input array, with adjacent windows shifted by a single row or column (or an index of a higher dimension).

Parameters

arr_in : ndarray, shape (M[, ...])

Input array.

window_shape : integer or tuple of length arr_in.ndim

Defines the shape of the elementary n-dimensional orthotope (better know as hyperrectangle [1]) of the rolling window view. If an integer is given, the shape will be a hypercube of sidelength given by its value.

step : integer or tuple of length arr_in.ndim

Indicates step size at which extraction shall be performed. If integer is given, then the step is uniform in all dimensions.

Returns

arr_out : ndarray

(rolling) window view of the input array.

Notes

One should be very careful with rolling views when it comes to memory usage. Indeed, although a 'view' has the same memory footprint as its base array, the actual array that emerges when this 'view' is used in a computation is generally a (much) larger array than the original, especially for 2-dimensional arrays and above.

For example, let us consider a 3 dimensional array of size (100, 100, 100) of float64. This array takes about 8*100**3 Bytes for storage which is just 8 MB. If one decides to build a rolling view on this array with a window of (3, 3, 3) the hypothetical size of the rolling view (if one was to reshape the view for example) would be 8*(100-3+1)**3*3**3 which is about 203 MB! The scaling becomes even worse as the dimension of the input array becomes larger.

Examples

import numpy as np
from skimage.util.shape import view_as_windows
A = np.arange(4*4).reshape(4,4)
A
window_shape = (2, 2)
B = view_as_windows(A, window_shape)
B[0, 0]
B[0, 1]
A = np.arange(10)
A
window_shape = (3,)
B = view_as_windows(A, window_shape)
B.shape
B
A = np.arange(5*4).reshape(5, 4)
A
window_shape = (4, 3)
B = view_as_windows(A, window_shape)
B.shape
B  # doctest: +NORMALIZE_WHITESPACE

Aliases

  • skimage.util.view_as_windows