votes up 1

mode must be 'mirror', 'constant', 'nearest' 'wrap' or 'interp'.

Package:
scipy
github stars 8546
Exception Class:
ValueError

Raise code

""" e='nearest'`:

    >>> savgol_filter(x, 5, 2, mode='nearest')
    array([1.74, 3.03, 3.54, 2.86, 0.66, 0.17, 1.  , 4.6 , 7.97])

    """
    if mode not in ["mirror", "constant", "nearest", "interp", "wrap"]:
        raise ValueError("mode must be 'mirror', 'constant', 'nearest' "
                         "'wrap' or 'interp'.")

    x = np.asarray(x)
    # Ensure that x is either single or double precision floating point.
    if x.dtype != np.float64 and x.dtype != np.float32:
        x = x.astype(np.float64)

    coef
😲 Agile task management is now easier than calling a taxi. #Tracklify

Ways to fix

votes up 2 votes down

Valid values of mode are 'mirror', 'constant', 'nearest' 'wrap' or 'interp'.

Sample code to reproduce the exception:

from scipy.signal import savgol_filter
np.set_printoptions(precision=2)  # For compact display.
x = np.array([2, 2, 5, 2, 1, 0, 1, 4, 9])
savgol_filter(x, 5, 2,mode='intrp')

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-37-d95df483f454> in <module>()  2 np.set_printoptions(precision=2) # For compact display.  3 x = np.array([2, 2, 5, 2, 1, 0, 1, 4, 9]) ----> 4 savgol_filter(x, 5, 2,mode='intrp') 
/usr/local/lib/python3.7/dist-packages/scipy/signal/_savitzky_golay.py in savgol_filter(x, window_length, polyorder, deriv, delta, axis, mode, cval)  327 """  328 if mode not in ["mirror", "constant", "nearest", "interp", "wrap"]: --> 329 raise ValueError("mode must be 'mirror', 'constant', 'nearest' "  330 "'wrap' or 'interp'.")  331  
ValueError: mode must be 'mirror', 'constant', 'nearest' 'wrap' or 'interp'.

Fixed version of the code :

from scipy.signal import savgol_filter
np.set_printoptions(precision=2)  # For compact display.
x = np.array([2, 2, 5, 2, 1, 0, 1, 4, 9])
savgol_filter(x, 5, 2,mode='interp')

array([1.66, 3.17, 3.54, 2.86, 0.66, 0.17, 1. , 4. , 9. ])

Dec 17, 2021 kellemnegasi answer
kellemnegasi 22.6k

Add a possible fix

Please authorize to post fix