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

Propadovic Nenad npropadovic at gmail.com
Thu Jun 22 04:45:54 EDT 2017


Hello Evgeni,
sorry, somehow initially I had not seen your post.
My OS is Windows 7 Professional N 64 bit.

Python 2.7.13 |Anaconda 4.3.0 (64-bit)
(yes I know Python 3.x is preferred, but that's the company choice that I
can't influence... )

numpy.__version__
Out[2]: '1.11.3'

scipy.__version__
Out[4]: '0.18.1'

Yeah, maybe I can update Anaconda before calling out a bug. But the
scipy-version is not soooo old.

And, yes, I'm aware of the brittle nature of exact equality of floats... I
often use code like following in my unit-tests:
assert (numpy.all(abs(x-x_maybe_equal ) < 1e-12))

Cheers,

Nenad

> Cannot repro -- what numpy/scipy versions, OS?
>
>
>
> In [2]: %paste
> 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
> ## -- End pasted text --
> [ 0.  0.  0.  1.  2.  3.  4.  4.  5.]
>
> In [3]: f(t) == sig
> Out[3]: array([ True,  True,  True,  True,  True,  True], dtype=bool)
>
> In [4]: numpy.__version__
> Out[4]: '1.10.4'
>
> In [5]: import scipy
>
> In [6]: scipy.__version__
> Out[6]: '1.0.0.dev0+f3e4e17'
>
>
> Also note that exact equality in floating point is brittle anyway:
>
> In [9]: f(t_new.astype(numpy.float32))
> Out[9]: array([ 0.,  0.,  0.,  1.,  2.,  3.,  4.,  4.,  4.])
>
> In [10]: f(t_new)
> Out[10]: array([ 0.,  0.,  0.,  1.,  2.,  3.,  4.,  4.,  5.])
>
>
> Evgeni
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-user/attachments/20170622/c5a5010e/attachment.html>


More information about the SciPy-User mailing list