#NEWLINE# @ cache #NEWLINE# def fix_length( data , size , axis = ( - 1 ) , **kwargs ) : #NEWLINE# #INDENT# "Fix the length an array `data` to exactly `size`.\n\n    If `data.shape[axis] < n`, pad according to the provided kwargs.\n    By default, `data` is padded with trailing zeros.\n\n    Examples\n    --------\n    >>> y = np.arange(7)\n    >>> # Default: pad with zeros\n    >>> librosa.util.fix_length(y, 10)\n    array([0, 1, 2, 3, 4, 5, 6, 0, 0, 0])\n    >>> # Trim to a desired length\n    >>> librosa.util.fix_length(y, 5)\n    array([0, 1, 2, 3, 4])\n    >>> # Use edge-padding instead of zeros\n    >>> librosa.util.fix_length(y, 10, mode='edge')\n    array([0, 1, 2, 3, 4, 5, 6, 6, 6, 6])\n\n    Parameters\n    ----------\n    data : np.ndarray\n      array to be length-adjusted\n\n    size : int >= 0 [scalar]\n      desired length of the array\n\n    axis : int, <= data.ndim\n      axis along which to fix length\n\n    kwargs : additional keyword arguments\n        Parameters to `np.pad()`\n\n    Returns\n    -------\n    data_fixed : np.ndarray [shape=data.shape]\n        `data` either trimmed or padded to length `size`\n        along the specified axis.\n\n    See Also\n    --------\n    numpy.pad\n    " #NEWLINE# kwargs . setdefault ( 'mode' , 'constant' ) #NEWLINE# n = data . shape [ axis ] #NEWLINE# if ( n > size ) : #NEWLINE# #INDENT# slices = ( [ slice ( None ) ] * data . ndim ) #NEWLINE# slices [ axis ] = slice ( 0 , size ) #NEWLINE# return data [ slices ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( n < size ) : #NEWLINE# #INDENT# lengths = ( [ ( 0 , 0 ) ] * data . ndim ) #NEWLINE# lengths [ axis ] = ( 0 , ( size - n ) ) #NEWLINE# return np . pad ( data , lengths , ** kwargs ) #NEWLINE# #UNINDENT# #UNINDENT# return data