nnmnkwii.preprocessing.adjust_frame_length(x, pad=True, divisible_by=1, **kwargs)[source]

Adjust frame length given a feature vector or matrix.

This adjust the number of frames of a given feature vector or matrix to be divisible by divisible_by by padding to the end or removing the last few frames. Default uses zero-padding.

  • x (numpy.ndarray) – Input 1d or 2d array, shape (T, or T x D).

  • pad (bool) – If True, pads values to the end, otherwise removes last few frames to ensure same frame lengths.

  • divisible_by (int) – If divisible_by > 0, number of frames will be adjusted to be divisible by divisible_by.

  • kwargs (dict) – Keyword argments passed to numpy.pad(). Default is mode = constant, which means zero padding.


adjusted array, of each shape (T or T' x D).

Return type



>>> from nnmnkwii.preprocessing import adjust_frame_length
>>> import numpy as np
>>> x = np.zeros((10, 1))
>>> x = adjust_frame_length(x, pad=True, divisible_by=3)
>>> assert x.shape[0] == 12