python - Does scipy.interpolate.interp1d have problems with decimal values leading the x values? -


i'm trying use interp1d() scipy interpolate data, keep hitting out or range error. after hours of googling, know x values not in increasing order cause same error i'm getting i've made sure that's not problem. far can tell, looks interp1d() doesn't decimals in first value. missing something?

a simplified version of problem:

the following runs fine.

import numpy np scipy.interpolate import interp1d  interp1d(np.array([1, 2, 3, 4, 5, 6]),          np.array([2, 4, 6, 8, 10, 12]), kind='cubic')(np.linspace(1, 6, num=40)) 

but, this:

interp1d(np.array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6]),      np.array([2, 4, 6, 8, 10, 12]), kind='cubic')(np.linspace(1, 6, num=40)) 

returns:

valueerror: value in x_new below interpolation range.

but, works fine.

interp1d(np.array([1.0, 2.2, 3.3, 4.4, 5.5, 6.6]),          np.array([2, 4, 6, 8, 10, 12]), kind='cubic')(np.linspace(1, 6, num=40)) 

inter1d returns function allows interpolate within domain of data. when use

interp1d(np.array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6]),      np.array([2, 4, 6, 8, 10, 12]), kind='cubic')(np.linspace(1, 6, num=40)) 

the domain of data interval [1.1, 6.6], minimum maximum values of x-values.

since 1 in np.linspace(1, 6, num=40) , 1 lies outside [1.1, 6.6], interp1d raises

valueerror: value in x_new below interpolation range. 

when try interpolate data @ x-values np.linspace(1, 6, num=40).

when change x-values of data

np.array([1.0, 2.2, 3.3, 4.4, 5.5, 6.6]) 

then domain of data expanded [1.0, 6.6], includes 1. hence, interpolating @ np.linspace(1, 6, num=40) works.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -