[SciPy-User] interpolate.interp1d - constructing a cubic interpolator is Slllooooooow.
Eraldo Pomponi
eraldo.pomponi at gmail.com
Thu Jan 15 04:49:22 EST 2015
Dear Andrew,
On Thu, Jan 15, 2015 at 9:46 AM, Andrew Nelson <andyfaff at gmail.com> wrote:
> I'm intending to use interpolation in a curvefitting function. So have
> been investigating the use of interpolate.interp1d.
> I'd prefer to use cubic interpolation but it seems to take ages:
>
> import numpy as np
>
> from scipy.interpolate import interp1d
>
> a = np.linspace(-2 * np.pi, 2 * np.pi, 1000)
>
> b = np.cos(a)
>
> %timeit interp1d(a, b)
>
> 10000 loops, best of 3: 71.6 µs per loop
>
> %timeit interp1d(a, b, kind='cubic')
>
> 1 loops, best of 3: 5.15 s per loop
>
>
> I'm wondering why it takes 5 orders of magnitude (x72000) longer to
> calculate a cubic interpolator than a linear interpolator?
>
I can reproduce your results but I cannot comment on the reason why there
exist a so big difference between the two cases. On the other hand,
following the documentation, I would go for the use of the more recent
UnivariateSpline (
http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.UnivariateSpline.html#scipy.interpolate.UnivariateSpline)
class that doesn't have this drawback. On my system, following your
example, I get:
%timeit spl = UnivariateSpline(a,b,k=3)
1000 loops, best of 3: 271 µs per loop
Cheers,
Eraldo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150115/bd010206/attachment.html>
More information about the SciPy-User
mailing list