[SciPy-User] UnivariateSpline broken?

Robert Elsner mlist@re-factory...
Fri Jun 4 07:30:09 CDT 2010


the UnivariateSpline implementation in scipy.interpolate seems to be
broken (tested on 0.7). It just produces garbage for some use cases
especially with logarithmic spacing of the x values.
A sample script to illustrate the problem is here. Am I misusing the
code or is it a bug?


import numpy as np
from scipy.interpolate import UnivariateSpline, splrep, splev

# Works as expected
x = np.logspace(-4, 1)
y = x**2

sp_1 = UnivariateSpline(x,y,k=3)
print np.all((sp_1(x) - y) < 1e-10 )

# Doesn't work as expected
y = np.sin(x)
sp_2 = UnivariateSpline(x,y,k=3)
print np.all((sp_2(x) - y) < 1e-10 )

# Works if using low-level routines
tck = splrep(x,y,k=3)
print np.all((splev(x, tck) - y) < 1e-10 )

More information about the SciPy-User mailing list