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

Oleksandr Huziy guziy.sasha at gmail.com
Wed Jun 21 10:19:29 EDT 2017


Hi Nenad:

This probably how the kind="zero" is implemented (uses a constant value
from the left side of the interval) and since in your case you do not have
any data to the right of the point, it is never used.

Maybe it could be called bug.... (You could try to submit an issue on
github)

Apparently, now for it to work as you want, you would need to extend your
sig a bit:

import numpy
from scipy.interpolate import interp1d
t = numpy.array([0.000, 0.004, 0.008, 0.012, 0.016, 0.02, 0.03])
sig = numpy.array([0, 1, 2, 3, 4, 5, 6])
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)
[ 0.  0.  0.  1.  2.  3.  4.  4.  5.]


Cheers






2017-06-21 9:41 GMT-04:00 Propadovic Nenad <npropadovic at gmail.com>:

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


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


More information about the SciPy-User mailing list