def trim_zeros_frames(x, eps=1e-7):
"""Remove trailling zeros frames.
Similar to :func:`numpy.trim_zeros`, trimming trailing zeros features.
Args:
x (numpy.ndarray): Feature matrix, shape (``T x D``)
eps (float): Values smaller than ``eps`` considered as zeros.
Returns:
numpy.ndarray: Trimmed 2d feature matrix, shape (``T' x D``)
Examples:
>>> import numpy as np
>>> from nnmnkwii.preprocessing import trim_zeros_frames
>>> x = np.random.rand(100,10)
>>> y = trim_zeros_frames(x)
"""
T, D = x.shape
s = np.sum(np.abs(x), axis=1)
s[s < eps] = 0.
return x[: len(np.trim_zeros(s))]
评论列表
文章目录