nnmnkwii.preprocessing.adjust_frame_length¶
-
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.- Parameters
x (numpy.ndarray) – Input 1d or 2d array, shape (
T,
orT 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 bydivisible_by
.kwargs (dict) – Keyword argments passed to
numpy.pad()
. Default is mode =constant
, which means zero padding.
- Returns
adjusted array, of each shape (
T
orT' x D
).- Return type
Examples
>>> 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