votes up 1

incorrect filter size

Package:
scipy
github stars 8546
Exception Class:
RuntimeError

Raise code

""" 
    >>> from scipy.ndimage import uniform_filter1d
    >>> uniform_filter1d([2, 8, 0, 4, 1, 9, 9, 0], size=3)
    array([4, 3, 4, 1, 4, 6, 6, 3])
    """
    input = numpy.asarray(input)
    axis = normalize_axis_index(axis, input.ndim)
    if size < 1:
        raise RuntimeError('incorrect filter size')
    complex_output = input.dtype.kind == 'c'
    output = _ni_support._get_output(output, input,
                                     complex_output=complex_output)
    if (size // 2 + origin < 0) or (size // 2 + origin >= size):
        raise ValueError('invalid origin')
    mode = _ni_support._extend_mode_to_code(mode)
    if not complex_output:

Ways to fix

votes up 1 votes down

filter size shouldn't be less than 1, as in the following sample code.

from scipy.ndimage import minimum_filter1d
minimum_filter1d([28041990], size=0)

The error output from the above sample code

---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-69-7fa369b30679> in <module>()  1 from scipy.ndimage import minimum_filter1d ----> 2 minimum_filter1d([2, 8, 0, 4, 1, 9, 9, 0], size=0) 
/usr/local/lib/python3.7/dist-packages/scipy/ndimage/filters.py in minimum_filter1d(input, size, axis, output, mode, cval, origin)  1011 axis = normalize_axis_index(axis, input.ndim)  1012 if size < 1: -> 1013 raise RuntimeError('incorrect filter size')  1014 output = _ni_support._get_output(output, input)  1015 if (size // 2 + origin < 0) or (size // 2 + origin >= size): 
RuntimeError: incorrect filter size

Fixed(working) code:

from scipy.ndimage import minimum_filter1d
minimum_filter1d([28041990], size=3)

array([2, 0, 0, 0, 1, 1, 0, 0])

Nov 24, 2021 kellemnegasi answer
kellemnegasi 18.3k

Add a possible fix

Please authorize to post fix