[SciPy-user] problem with interp1d

John Hunter jdhunter at ace.bsd.uchicago.edu
Tue Sep 12 09:08:43 CDT 2006

>>>>> "John" == John Hunter <jdhunter at ace.bsd.uchicago.edu> writes:

    John> I thought the following code would resample the irregularly
    John> spaced 't' to the regularly spaced 'newt' but I am getting a
    John> traceback

OK, please ignore me.  Because I was using randn to generate the
intervals, I was getting non-monotonic x.  Duh

import scipy
import scipy.interpolate
t = scipy.cumsum(scipy.rand(100)) # increasing time
s = scipy.sin(0.1*2*scipy.pi*t)
interp = scipy.interpolate.interp1d(t, s)
newt = scipy.arange(min(t), max(t), 0.1)
news = interp(newt)

from pylab import subplot, show
ax = subplot(111)
ax.plot(t, s, 'o', newt, news, '-')

More information about the SciPy-user mailing list