1

I am trying to perform linear extrapolation using the left and right parameters of numpy.interp.

The docs list these parameters as an "optional float or complex corresponding to fp."

My strategy is as follows, shown for left:

f = numpy.interp(x, xp, fp, left=(x-xp[-1])*(fp[-1]-fp[-2])/(xp[-1]-xp[-2])+fp[-1], right=...)

This works just fine for single points x, but how do I format left if I want to input a vector for x (to calculate multiple f's simultaneously)? I have tried inputting the whole vector x into the above expression but received a TypeError.

mfgeng
  • 89
  • 5
  • In the documentation it mentions that a ValueError is raised if the shapes are incompatible, so your input is likely not of type `np.ndarray`. Could you provide the full traceback? – Philip Ciunkiewicz May 01 '21 at 04:18
  • related: https://stackoverflow.com/q/19406049 – djvg Jan 20 '23 at 22:20

0 Answers0