The pad.py module contains a group of functions to pad values onto the edges of an n-dimensional array.

PYME.contrib.pad.pad.with_minimum(matrix, pad_width=(1, ), stat_len=None)

Pads with the minimum value of all or part of the vector along each axis.

Parameters: matrix : array_like of rank N Input array pad_width : {tuple of N tuples(before, after), tuple(both,)}, optional How many values padded to each end of the vector for each axis. ((before, after),) * np.rank(matrix) (pad,) is a shortcut for before = after = pad for all axes Default is (1, ). stat_len : {tuple of N tuples(before, after), tuple(both,)}, optional How many values at each end of vector to determine the statistic. ((before_len, after_len),) * np.rank(matrix) (len,) is a shortcut for before = after = len for all dimensions None uses the entire vector. Default is None. out : ndarray of rank N Padded array.

pad.with_maximum, pad.with_median, pad.with_mean, pad.with_constant, pad.with_linear_ramp, pad.with_reflect, pad.with_wrap

Examples

>>> import pad
>>> a = [1, 2, 3, 4, 5, 6]
array([1, 1, 1, 2, 3, 4, 5, 6, 1, 1])

>>> pad.with_minimum(a, (4, 2))
array([1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 1, 1])

>>> a = [[1,2], [3,4]]
>>> pad.with_minimum(a, ((3, 2), (2, 3)))
array([[1, 1, 1, 2, 1, 1, 1],
[1, 1, 1, 2, 1, 1, 1],
[1, 1, 1, 2, 1, 1, 1],
[1, 1, 1, 2, 1, 1, 1],
[3, 3, 3, 4, 3, 3, 3],
[1, 1, 1, 2, 1, 1, 1],
[1, 1, 1, 2, 1, 1, 1]])

PYME.contrib.pad.pad.with_maximum(matrix, pad_width=(1, ), stat_len=None)

Pads with the maximum value of all or part of the vector along each axis.

Parameters: matrix : array_like of rank N Input array pad_width : {tuple of N tuples(before, after), tuple(pad,)}, optional How many values padded to each end of the vector for each axis. ((before, after),) * np.rank(matrix) (pad,) is a shortcut for before = after = pad for all axes Default is (1, ). stat_len : {tuple of N tuples(before, after), tuple(len,)}, optional How many values at each end of vector to determine the statistic. ((before_len, after_len),) * np.rank(matrix) (len,) is a shortcut for before = after = len for all dimensions None uses the entire vector. Default is None. out : ndarray of rank N Padded array.

pad.with_minimum, pad.with_median, pad.with_mean, pad.with_constant, pad.with_linear_ramp, pad.with_reflect, pad.with_wrap

Examples

>>> import pad
>>> a = [1, 2, 3, 4, 5]
array([5, 5, 1, 2, 3, 4, 5, 5, 5])

>>> pad.with_maximum(a, (1, 7))
array([5, 1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5])

>>> pad.with_maximum(a, (0, 7))
array([1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5])

PYME.contrib.pad.pad.with_mean(matrix, pad_width=(1, ), stat_len=None)

Pads with the mean value of all or part of the vector along each axis.

Parameters: matrix : array_like of rank N Input array pad_width : {tuple of N tuples(before, after), tuple(both,)}, optional How many values padded to each end of the vector for each axis. ((before, after),) * np.rank(matrix) (pad,) is a shortcut for before = after = pad for all axes Default is (1, ). stat_len : {tuple of N tuples(before, after), tuple(both,)}, optional How many values at each end of vector to determine the statistic. ((before_len, after_len),) * np.rank(matrix) (len,) is a shortcut for before = after = len for all dimensions None uses the entire vector. Default is None. out : ndarray of rank N Padded array.

pad.with_maximum, pad.with_minimum, pad.with_median, pad.with_constant, pad.with_linear_ramp, pad.with_reflect, pad.with_wrap

Examples

>>> import pad
>>> a = [1, 2, 3, 4, 5]
array([3, 3, 1, 2, 3, 4, 5, 3, 3])

PYME.contrib.pad.pad.with_median(matrix, pad_width=(1, ), stat_len=None)

Pads with the median value of all or part of the vector along each axis.

Parameters: matrix : array_like of rank N Input array pad_width : {tuple of N tuples(before, after), tuple(both,)}, optional How many values padded to each end of the vector for each axis. ((before, after),) * np.rank(matrix) (pad,) is a shortcut for before = after = pad for all axes Default is (1, ). stat_len : {tuple of N tuples(before, after), tuple(both,)}, optional How many values at each end of vector to determine the statistic. ((before_len, after_len),) * np.rank(matrix) (len,) is a shortcut for before = after = len for all dimensions None uses the entire vector. Default is None. out : ndarray of rank N Padded array.

pad.with_maximum, pad.with_minimum, pad.with_mean, pad.with_constant, pad.with_linear_ramp, pad.with_reflect, pad.with_wrap

Examples

>>> import pad
>>> a = [1, 2, 3, 4, 5]
array([3, 3, 1, 2, 3, 4, 5, 3, 3])

>>> pad.with_median(a, (4, 0))
array([3, 3, 3, 3, 1, 2, 3, 4, 5])

PYME.contrib.pad.pad.with_linear_ramp(matrix, pad_width=(1, ), end_value=(0, ))

Pads with the linear ramp between end_value and the begining/end of the vector along each axis.

Parameters: matrix : array_like of rank N Input array pad_width : {tuple of N tuples(before, after), tuple(both,)}, optional How many values padded to each end of the vector for each axis. ((before, after),) * np.rank(matrix) (pad,) is a shortcut for before = after = pad for all axes Default is (1, ). end_value : {tuple of N tuples(before, after), tuple(both,)}, optional What value should the padded values end with. ((before_len, after_len),) * np.rank(matrix) (len,) is a shortcut for before = after = len for all dimensions None uses the entire vector. Default is None. out : ndarray of rank N Padded array.

pad.with_maximum, pad.with_minimum, pad.with_median, pad.with_mean, pad.with_constant, pad.with_reflect, pad.with_wrap

Examples

>>> import pad
>>> a = [1, 2, 3, 4, 5]
array([ 5,  3,  1,  2,  3,  4,  5,  2, -1, -4])

PYME.contrib.pad.pad.with_reflect(matrix, pad_width=(1, ))

Pads with the reflection of the vector mirrored on the first and last values of the vector along each axis.

Parameters: matrix : array_like of rank N Input array pad_width : {tuple of N tuples(before, after), tuple(both,)}, optional How many values padded to each end of the vector for each axis. ((before, after),) * np.rank(matrix) (pad,) is a shortcut for before = after = pad for all axes Default is (1, ). out : ndarray of rank N Padded array.

pad.with_maximum, pad.with_minimum, pad.with_median, pad.with_mean, pad.with_constant, pad.with_linear_ramp, pad.with_wrap

Examples

>>> import pad
>>> a = [1, 2, 3, 4, 5]
array([3, 2, 1, 2, 3, 4, 5, 4, 3, 2])

PYME.contrib.pad.pad.with_constant(matrix, pad_width=(1, ), constant_values=(0, ))

Parameters: matrix : array_like of rank N Input array pad_width : {tuple of N tuples(before, after), tuple(both,)}, optional How many values padded to each end of the vector for each axis. ((before, after),) * np.rank(matrix) (pad,) is a shortcut for before = after = pad for all axes Default is (1, ). constant_values : {tuple of N tuples(before, after), tuple(both,)}, optional The values to set the padded values to. ((before_len, after_len),) * np.rank(matrix) (len,) is a shortcut for before = after = len for all dimensions None uses the entire vector. Default is None. out : ndarray of rank N Padded array.

pad.with_maximum, pad.with_minimum, pad.with_median, pad.with_mean, pad.with_linear_ramp, pad.with_reflect, pad.with_wrap

Examples

>>> import pad
>>> a = [1, 2, 3, 4, 5]
array([4, 4, 1, 2, 3, 4, 5, 6, 6, 6])

PYME.contrib.pad.pad.with_wrap(matrix, pad_width=(1, ))

Pads with the wrap of the vector along the axis. The first values are used to pad the end and the end values are used to pad the beginning.

Parameters: matrix : array_like of rank N Input array pad_width : {tuple of N tuples(before, after), tuple(both,)}, optional How many values padded to each end of the vector for each axis. ((before, after),) * np.rank(matrix) (pad,) is a shortcut for before = after = pad for all axes Default is (1, ). out : ndarray of rank N Padded array.

pad.with_maximum, pad.with_minimum, pad.with_median, pad.with_mean, pad.with_constant, pad.with_linear_ramp, pad.with_reflect, pad.with_wrap
>>> import pad