Hi, I am having problems with the spline functions from scipy.interpolate. Reading the doc strings I expected the following to work: from scipy.interpolate import splev,splrep import numpy as N x = N.linspace(-4,10,5) y = x**2 t,c,l = splrep(x,y,xb=0,xe=4) Traceback (most recent call last): File "C:\pythonxy\python\lib\site-packages\scipy\interpolate\fitpack.py", line 406, in splrep n,c,fp,ier = dfitpack.curfit(task, x, y, w, t, wrk, iwrk, xb, xe, k, s) error: (xb<=x[0]) failed for 1st keyword xb Second, I want to fit several curves using the same knots, thus I tried the following: y2 = x**2-3*x+4 t2,c2,l2 = splrep(x,y2,t=t) Traceback (most recent call last): File "C:\pythonxy\python\lib\site-packages\scipy\interpolate\fitpack.py", line 418, in splrep raise _iermess[ier][1],_iermess[ier][0] ValueError: Error on input data Are those bugs or am I misunderstanding something? Eventually I would like to morph one spline into another, therefor I want to stick with the knots. If anyone has experiences with splines and morphing I would be very interested to hear about it. Regards, Christian
Hi Christian, About the first error... On Fri, Apr 17, 2009 at 4:14 AM, Christian K. <ckkart@hoc.net> wrote:
Hi,
I am having problems with the spline functions from scipy.interpolate. Reading the doc strings I expected the following to work:
from scipy.interpolate import splev,splrep import numpy as N x = N.linspace(-4,10,5) y = x**2 t,c,l = splrep(x,y,xb=0,xe=4)
Traceback (most recent call last): File "C:\pythonxy\python\lib\site-packages\scipy\interpolate\fitpack.py", line 406, in splrep n,c,fp,ier = dfitpack.curfit(task, x, y, w, t, wrk, iwrk, xb, xe, k, s) error: (xb<=x[0]) failed for 1st keyword xb
The error message is telling you what the problem is. From the docstring: Given the set of data points (x[i], y[i]) determine a smooth spline approximation of degree k on the interval xb <= x <= xe. You have values in your x array outside the interval [xb,xe]. Warren
Hi Warren, Warren Weckesser schrieb:
About the first error...
On Fri, Apr 17, 2009 at 4:14 AM, Christian K. <ckkart@hoc.net <mailto:ckkart@hoc.net>> wrote:
Hi,
I am having problems with the spline functions from scipy.interpolate. Reading the doc strings I expected the following to work:
from scipy.interpolate import splev,splrep import numpy as N x = N.linspace(-4,10,5) y = x**2 t,c,l = splrep(x,y,xb=0,xe=4)
Traceback (most recent call last): File "C:\pythonxy\python\lib\site-packages\scipy\interpolate\fitpack.py", line 406, in splrep n,c,fp,ier = dfitpack.curfit(task, x, y, w, t, wrk, iwrk, xb, xe, k, s) error: (xb<=x[0]) failed for 1st keyword xb
The error message is telling you what the problem is. From the docstring:
Given the set of data points (x[i], y[i]) determine a smooth spline approximation of degree k on the interval xb <= x <= xe.
You have values in your x array outside the interval [xb,xe].
Right, but then I don't get the meaning of xb and xe at all. What sense does it make to choose a fit interval larger than the input data? IMHO x[0] < xb < xe < x[-1] should hold but obviously the docs tell the opposite. Christian
On 18-Apr-09, at 9:31 AM, Christian K. wrote:
Right, but then I don't get the meaning of xb and xe at all. What sense does it make to choose a fit interval larger than the input data? IMHO x[0] < xb < xe < x[-1] should hold but obviously the docs tell the opposite.
What sense does it make to fit using a smaller interval than x[0] ... x[-1]? You'd then be throwing away some of your observations. An xb and xe value < or > might do something I don't see why you're specifying xb and xe to begin with. If you're fitting it to all the data, simply omitting those arguments makes most sense. You can slice your input arrays if you'd prefer not to use all of your data. David
Hi, I'm stumbling on xb and xe as well.
Right, but then I don't get the meaning of xb and xe at all. What sense does it make to choose a fit interval larger than the input data? IMHO x[0] < xb < xe < x[-1] should hold but obviously the docs tell the opposite.
What sense does it make to fit using a smaller interval than x[0] ... x[-1]? You'd then be throwing away some of your observations. An xb and xe value < or > might do something
I don't see why you're specifying xb and xe to begin with. If you're fitting it to all the data, simply omitting those arguments makes most sense. You can slice your input arrays if you'd prefer not to use all of your data.
What sense does it make to fit using a _bigger_ interval than x[0]...x[-1]? There are no more data points, so there is nothing more to fit to however much you extend the interval, right? Of course, slicing the input arrays is an acceptable workaround, if I want to fit only part of my data (which, indeed, I quite often want to do). But if xb, xe are not intended to limit that interval, they look perfectly useless to me. Thanks for any future enlightenment! Christine
participants (4)
-
Christian K.
-
Christine
-
David Warde-Farley
-
Warren Weckesser