4

Despite scipy's documentation indicating that scipy.interpolate.UnivariateSpline will run on order k<=5, under the hood there is an additional constraint for order >=1. Does anyone know of a way to achieve either 0-degree spline or piecewise constant interpolation with Numpy/Scipy?

Benjamin
  • 11,560
  • 13
  • 70
  • 119

2 Answers2

3

You can use interp1d with kind='zero' or kind='nearest'.

Daniel
  • 42,087
  • 4
  • 55
  • 81
ev-br
  • 24,968
  • 9
  • 65
  • 78
-1

I have tried a simple trick 1) do numerical integration of step-wise constant function and you will get broken line 2) use 1. degree spline fit 3) calculate a derivative of the spline (method .derivative())

it has worked, but it could be better.

Tomas
  • 91
  • 2