nnAudio.librosa_functions.pad_center¶
- nnAudio.librosa_functions.pad_center(data, size, axis=- 1, **kwargs)¶
Wrapper for np.pad to automatically center an array prior to padding. This is analogous to str.center()
Examples
>>> # Generate a vector >>> data = np.ones(5) >>> librosa.util.pad_center(data, 10, mode='constant') array([ 0., 0., 1., 1., 1., 1., 1., 0., 0., 0.])
>>> # Pad a matrix along its first dimension >>> data = np.ones((3, 5)) >>> librosa.util.pad_center(data, 7, axis=0) array([[ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.]]) >>> # Or its second dimension >>> librosa.util.pad_center(data, 7, axis=1) array([[ 0., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 0.], [ 0., 1., 1., 1., 1., 1., 0.]])
- Parameters
data (np.ndarray) – Vector to be padded and centered
size (int >= len(data) [scalar]) – Length to pad data
axis (int) – Axis along which to pad and center the data
kwargs (additional keyword arguments) – arguments passed to np.pad()
- Returns
data_padded – data centered and padded to length size along the specified axis
- Return type
np.ndarray
- Raises
ParameterError – If size < data.shape[axis]
See also
numpy.pad