PYME.contrib.pad.pad module

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_constant(matrix, pad_width=(1,), constant_values=(0,))

Pads with a constant value.

Parameters
matrixarray_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.

Returns
outndarray of rank N

Padded array.

See also

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]
>>> pad.with_constant(a, (2,3), (4,6))
array([4, 4, 1, 2, 3, 4, 5, 6, 6, 6])
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
matrixarray_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.

Returns
outndarray of rank N

Padded array.

See also

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]
>>> pad.with_linear_ramp(a, (2,3), (5,-4))
array([ 5,  3,  1,  2,  3,  4,  5,  2, -1, -4])
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
matrixarray_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.

Returns
outndarray of rank N

Padded array.

See also

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]
>>> pad.with_maximum(a, (2,))
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
matrixarray_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.

Returns
outndarray of rank N

Padded array.

See also

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]
>>> pad.with_mean(a, (2,))
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
matrixarray_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.

Returns
outndarray of rank N

Padded array.

See also

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]
>>> pad.with_median(a, (2,))
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_minimum(matrix, pad_width=(1,), stat_len=None)

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

Parameters
matrixarray_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.

Returns
outndarray of rank N

Padded array.

See also

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]
>>> pad.with_minimum(a, (2,))
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_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
matrixarray_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, ).

Returns
outndarray of rank N

Padded array.

See also

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]
>>> pad.with_reflect(a, (2,3))
array([3, 2, 1, 2, 3, 4, 5, 4, 3, 2])
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
matrixarray_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, ).

Returns
outndarray of rank N

Padded array.

See also

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

Examples

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