ertk.utils.frame_array

ertk.utils.frame_array(x: ndarray, frame_size: int, frame_shift: int, pad: bool = False, axis: int = 0, copy: bool = True) ndarray

Frames an array over a given axis with optional padding and copying.

Parameters:
x: np.ndarray

Array to frame.

frame_size: int

Width of frame.

frame_shift: int

Amount each window is moved for subsequent frames.

pad: bool

If the frames don’t neatly fit the axis length, this indicated whether to pad or cut the remaining length. Default is False which means any remaining length is cut. If pad=True then any remaining length is padded with zeros and an additional frame is produced. If frames neatly fit into the axis length then this option has no effect.

axis: int

Axis to frame over. Default is 0.

copy: bool

Whether to copy and return a contiguous array (more memory usage). Default is True so that a contiguous copy is retured. Note: if copy=False it is assumed that the input array is contiguous so that a view with modified strides can be properly created.

Returns:
frames: np.ndarray

The resulting frames. If copy=False then these are read-only views into x, otherwise a contiguous array is returned.