vak.transforms.functional.view_as_window_batch#

vak.transforms.functional.view_as_window_batch(arr, window_width)[source]#

return view of a 1d or 2d array as a batch of non-overlapping windows

Parameters:
  • arr (numpy.ndarray) – with 1 or 2 dimensions, e.g. a vector of labeled timebins or a 2-d array representing a spectrogram. If the array has 2-d dimensions, the returned array will have dimensions (batch, height of array, window width)

  • window_width (int) – width of window in number of elements.

Returns:

batch_windows – with shape (batch size, window_size) if array is 1d, or with shape (batch size, height, window_size) if array is 2d. Batch size will be arr.shape[-1] // window_width. Window width must divide arr.shape[-1] evenly. To pad the array so it can be divided into windows of the specified width, use the pad_to_window transform

Return type:

numpy.ndarray

Notes

adapted from skimage.util.view_as_blocks https://github.com/scikit-image/scikit-image/blob/f1b7cf60fb80822849129cb76269b75b8ef18db1/skimage/util/shape.py#L9