Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Built-in function scipy.signal.savgol_filter returns error

I am trying to filter a data set using the scipy.signal.savgol_filter function, but I get the error

TypeError: expected x and y to have same length

when I try to assign the data in a new list.

What is stranger is that just before my last computation everything worked as intended, but now I get this. I have tried to create an empty list the size of the filtered one, but I get the same error.

Here is that part of my code:

import scipy as sc
import scipy.signal
Cf = sc.signal.savgol_filter(x=C, window_length=299, polyorder=3)

where C is a well defined list of float type numbers.

like image 474
ivancha32 Avatar asked Apr 23 '17 19:04

ivancha32


1 Answers

I get the error that you reported if the window_length is greater than the length of C (e.g. savgol_filter([3, 1, 4, 1, 5, 9], window_length=7, polyorder=3)).

In SciPy 1.0.0, the cryptic error message has been replaced with a more informative message:

ValueError: If mode is 'interp', window_length must be less than
or equal to the size of x.
like image 115
Warren Weckesser Avatar answered Oct 08 '22 15:10

Warren Weckesser