Density.pad#
- Density.pad(new_shape, center=True, padding_value=0)[source]#
Density.pad()extends the internalDensity.dataarray of the currentDensityinstance tonew_shapeand adaptsDensity.originaccordingly.- Parameters:
- new_shapetuple of int
The desired shape for the new volume.
- centerbool, optional
Whether the data should be centered in the new box. Default is True.
- padding_valuefloat, optional
Value to pad the data array with. Default is zero.
- Raises:
- ValueError
If the length of
new_shapedoes not match the dimensionality ofDensity.data.
Examples
The following demonstrates the functionality of
Density.pad()on a one-dimensional array:>>> import numpy as np >>> from tme import Density >>> dens = Density(np.array([1,1,1])) >>> dens.pad(new_shape = (5,), center = True) >>> dens.data array([0, 1, 1, 1, 0])
If
centeris set to False, the padding values will be appended:>>> dens = Density(np.array([1,1,1])) >>> dens.pad(new_shape = (5,), center = False) >>> dens.data array([1, 1, 1, 0, 0])
It’s also possible to pass a user-defined
padding_value:>>> dens = Density(np.array([1,1,1])) >>> dens.pad(new_shape = (5,), center = True, padding_value = -1) >>> dens.data array([-1, 1, 1, 1, -1])