Density.pad#

Density.pad(new_shape, center=True, padding_value=0)[source]#

Density.pad() extends the internal Density.data array of the current Density instance to new_shape and adapts Density.origin accordingly.

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_shape does not match the dimensionality of Density.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 center is 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])