nnmnkwii.preprocessing.adjust_frame_lengths(x, y, pad=True, ensure_even=False, divisible_by=1, **kwargs)[source]

Adjust frame lengths given two feature vectors or matrices.

This ensures that two feature vectors or matrices have same number of frames, by padding to the end or removing the last few frames. Default uses zero-padding.


ensure_even is deprecated and will be removed in v0.1.0. Use divisible_by=2 instead.

  • x (numpy.ndarray) – Input 2d feature matrix, shape (T^1 x D).

  • y (numpy.ndarray) – Input 2d feature matrix, shape (T^2 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.


Pair of adjusted feature matrices, of each shape (T x D).

Return type



>>> from nnmnkwii.preprocessing import adjust_frame_lengths
>>> import numpy as np
>>> x = np.zeros((10, 1))
>>> y = np.zeros((11, 1))
>>> x, y = adjust_frame_lengths(x, y)
>>> assert len(x) == len(y)