Signal processing base functions

Signal processing basic functionalities on numpy arrays.

scared.signal_processing.base.pad(array, target_shape, offsets=None, pad_with=0)[source]

Pad a given array with ‘pad_with’ values, according to the given shape.

Parameters:
  • array (numpy.ndarray) – data to be padded.

  • target_shape (list, tuple or ndarray) – shape of the output.

  • offsets (list, tuple or ndarray) – of length array.ndim), offsets where to place ‘array’ (default: None). If ‘None’, all offsets are 0.

  • pad_with (compatible with array.dtype) – value used to pad (default: 0).

Returns:

A new array being filled with the correct parameters.

Return type:

(numpy.ndarray)

Example

>>> a = np.array([[10, 11, 12], [13, 14, 15]])
>>> a
array([[10, 11, 12],
       [13, 14, 15]])
>>> pad(a, (5, 5), offsets=[0, 0])
array([[10, 11, 12,  0,  0],
       [13, 14, 15,  0,  0],
       [ 0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0]])
>>> pad(a, (5, 5), offsets=[1, 2])
array([[ 0,  0,  0,  0,  0],
       [ 0,  0, 10, 11, 12],
       [ 0,  0, 13, 14, 15],
       [ 0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0]])
scared.signal_processing.base.cast_array(array, dtype='float64')[source]

Cast ‘array’ to dtype.

Cast only if expected dtype is different than the current one. Useful for performance considerations.

Parameters:
  • array (numpy.ndarray) – ndarray to be casted.

  • dtype (numpy.dtype) – valid dtype (default: float64).

Returns:

The given array if no cast needed, or a new array with the correct cast.

Return type:

(numpy.ndarray)