[SciPy-User] interpolate.interp1d - constructing a cubic interpolator is Slllooooooow.

Andrew Nelson andyfaff at gmail.com
Thu Jan 15 06:04:51 EST 2015


Great, thanks.

I found that interpolate.InterpolatedUnivariateSpline is going to do the
job for me.

On 15 January 2015 at 20:49, Eraldo Pomponi <eraldo.pomponi at gmail.com>
wrote:

> 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
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>


-- 
_____________________________________
Dr. Andrew Nelson


_____________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150115/eadf67c8/attachment.html>


More information about the SciPy-User mailing list