votes up 1

invalid origin

Package:
scipy
github stars 8546
Exception Class:
ValueError

Raise code

    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:
        _nd_image.uniform_filter1d(input, size, axis, output, mode, cval,
                                   origin)
    else:
        _nd_image.uniform_filter1d(input.real, size, axis, output.real, mode,
                                   numpy.real(cval), origin)
😲 Agile task management is now easier than calling a taxi. #Tracklify

Ways to fix

votes up 2 votes down

Looking closely at the source code, this exception is raised when the following condition is not fulfilled.

size // 2 + origin < 0)

Or

(size // 2 + origin >= size

This means the cause of the exception are both size and origin.

Here is a sample that defies the second condition and raises this exception.

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

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-71-57e5dd8f7b5c> in <module>()  1 from scipy.ndimage import minimum_filter1d ----> 2 minimum_filter1d([2, 8, 0, 4, 1, 9, 9, 0], size=3,origin=3) 
/usr/local/lib/python3.7/dist-packages/scipy/ndimage/filters.py in minimum_filter1d(input, size, axis, output, mode, cval, origin)  1014 output = _ni_support._get_output(output, input)  1015 if (size // 2 + origin < 0) or (size // 2 + origin >= size): -> 1016 raise ValueError('invalid origin')  1017 mode = _ni_support._extend_mode_to_code(mode)  1018 _nd_image.min_or_max_filter1d(input, size, axis, output, mode, cval, 
ValueError: invalid origin

Fixed version of the code:

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

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

Nov 24, 2021 kellemnegasi answer
kellemnegasi 18.3k

Add a possible fix

Please authorize to post fix