[SciPy-User] Strange behaviour of scipy.interpolate.interp1d in with kind="zero"

Propadovic Nenad npropadovic at gmail.com
Wed Jun 21 09:41:26 EDT 2017


Hello everybody,

please consider the following code:

---
import numpy
from scipy.interpolate import interp1d

t = numpy.array([0.000, 0.004, 0.008, 0.012, 0.016, 0.02])
sig = numpy.array([0, 1, 2, 3, 4, 5])
t_new = numpy.array([0.0, 0.001, 0.003,  0.004,  0.008, 0.012,  0.016,
0.0196, 0.02])

f = interp1d(t, sig, kind='zero')
s_resampled = f(t_new)
print s_resampled
---

The result I get on my machine is:
>C:\Anaconda2\pythonw -u "test_zero_order_hold.py"
[ 0.  0.  0.  1.  2.  3.  4.  4.  4.]
>Exit code: 0

Now why is the last value 4, and not 5? I'd expect it to be 5, as the last
timestamps in t and t_new are identical. Is this a bug in interp1d or am I
missing something important - if so, what?

Thanks a lot, in advance,

Nenad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-user/attachments/20170621/2b4599f5/attachment.html>


More information about the SciPy-User mailing list