# [Scipy-tickets] [SciPy] #1824: scipy.insterpolate's splrep function fails with certain combinations of knots and number of datapoints

SciPy Trac scipy-tickets@scipy....
Sat Jan 26 00:51:21 CST 2013

```#1824: scipy.insterpolate's splrep function fails with certain combinations of
knots and number of datapoints
-------------------------------+--------------------------------------------
Reporter:  nespinoza          |       Owner:  pv
Priority:  normal             |   Milestone:  Unscheduled
Component:  scipy.interpolate  |     Version:  0.10.1
Keywords:                     |
-------------------------------+--------------------------------------------
I posted the problem originally on Stackexchange:
http://stackoverflow.com/questions/14533908/bug-on-selecting-knots-on-
scipy-insterpolates-splrep-function.

Basically, with certain combinations of numbers of data points and knots,
the code crashes with the error:

File "/usr/lib/python2.7/dist-packages/scipy/interpolate/fitpack.py", line
465, in
splrep raise _iermess[ier][1](_iermess[ier][0])
ValueError:     Error on input data

A code to reproduce this error:

{{{
import numpy as np
from scipy.interpolate import splrep,splev
# First we define the number of datapoints and knots:
ndata = 1931
nknots = 796
# Now we create a dataset which will be a curve made with a
# gaussian mixture:
x = np.arange(0,1,1./np.double(ndata))
means = np.random.uniform(0,1,10)
y = 0.0
for i in range(len(means)):
y = y+np.exp(-(x-means[i])**2./0.01)
# We add some noise to obtain the data:
data = y + np.random.normal(0,0.05,len(y))
# Now we crate the array of knots:
knots = np.arange(x[1],x[len(x)-1],(x[len(x)-1]-x[1])/np.double(nknots))
# And use splrep to get the b-spline representation:
tck = splrep(x,data,t=knots)
fit = splev(x,tck)
}}}

--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1824>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
```