[Numpy-discussion] confused about univaritespline
Neal Becker
ndbecker2 at gmail.com
Tue Nov 20 14:30:04 EST 2012
Pauli Virtanen wrote:
> 20.11.2012 21:11, Neal Becker kirjoitti:
>> import numpy as np
>> import matplotlib.pyplot as plt
>>
>> ibo = np.array ((12, 14, 16, 18, 20, 22, 24, 26, 28, 29, 29.8, 30.2))
>> gain_deriv = np.array ((0, 0, 0, 0, 0, 0, .2, .4, .5, .5, 0, -2))
>>
>> import scipy.interpolate
>> s = scipy.interpolate.UnivariateSpline(ibo, gain_deriv, s=0.1)
>>
>> xs = linspace(12, 31, 100)
>> gain = np.vectorize (lambda x: s.integral (12, x)) (xs)
>>
>> plot (xs, s(xs))
>> plot (xs, gain)
>
>>From fitpack/splint.f:
>
> c s(x) is considered to be identically zero outside
> c the interval (t(k+1),t(n-k)).
>
> Not documented in the Python wrapper, though.
>
Ah, thanks! Bitten one more by the fact that spline is not meant for
extrapolation, which here I had done inadvertantly.
IMO, if spline isn't intended to be used to extrapolate, I'd prefer it to throw.
More information about the NumPy-Discussion
mailing list