scipy.ndimage.generic_filter1d

scipy.ndimage.generic_filter1d(input, function, filter_size, axis=-1, output=None, mode='reflect', cval=0.0, origin=0, extra_arguments=(), extra_keywords=None)[source]

Calculate a one-dimensional filter along the given axis.

generic_filter1d iterates over the lines of the array, calling the given function at each line. The arguments of the line are the input line, and the output line. The input and output lines are 1D double arrays. The input line is extended appropriately according to the filter size and origin. The output line must be modified in-place with the result.

Parameters:

input : array_like

Input array to filter.

function : {callable, scipy.LowLevelCallable}

Function to apply along given axis.

filter_size : scalar

Length of the filter.

axis : int, optional

The axis of input along which to calculate. Default is -1.

output : array, optional

The output parameter passes an array in which to store the filter output. Output array should have different name as compared to input array to avoid aliasing errors.

mode : {‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, optional

The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to ‘constant’. Default is ‘reflect’

cval : scalar, optional

Value to fill past edges of input if mode is ‘constant’. Default is 0.0

origin : scalar, optional

The origin parameter controls the placement of the filter. Default 0.0.

extra_arguments : sequence, optional

Sequence of extra positional arguments to pass to passed function

extra_keywords : dict, optional

dict of extra keyword arguments to pass to passed function

Notes

This function also accepts low-level callback functions with one of the following signatures and wrapped in scipy.LowLevelCallable:

int function(double *input_line, npy_intp input_length,
             double *output_line, npy_intp output_length,
             void *user_data)
int function(double *input_line, intptr_t input_length,
             double *output_line, intptr_t output_length,
             void *user_data)

The calling function iterates over the lines of the input and output arrays, calling the callback function at each line. The current line is extended according to the border conditions set by the calling function, and the result is copied into the array that is passed through input_line. The length of the input line (after extension) is passed through input_length. The callback function should apply the filter and store the result in the array passed through output_line. The length of the output line is passed through output_length. user_data is the data pointer provided to scipy.LowLevelCallable as-is.

The callback function must return an integer error status that is zero if something went wrong and one otherwise. If an error occurs, you should normally set the python error status with an informative message before returning, otherwise a default error message is set by the calling function.

In addition, some other low-level function pointer specifications are accepted, but these are for backward compatibility only and should not be used in new code.