[SciPy-User] Replace duplicates in a monotonically increasing array with linearly interpolated values.

Dharhas Pothina Dharhas.Pothina@twdb.state.tx...
Fri Sep 10 15:32:19 CDT 2010


I may be missing something but I'm not seeing how that would work if the spacing was fairly irregular unlike my example array. I don't mind the interpolation not going through the switching points exactly but the points should not shift to the next interval which it seems would happen if the array was irregularly spaced.

> from scipy.interpolate import interp1d
> x = np.array([1.0,1.0,1.0,2.0,2.0,3.0,3.0,3.0,4.0,4.0,5.0,5.0,5.0,5.0,6.0])
> f = interp1d(range(len(np.unique(x))), np.unique(x))
> xnew = np.linspace(0,len(np.unique(x))-1,len(x)); f(xnew)
> plt.figure(); plt.plot(range(len(x)), x, 'o', range(len(x)), f(xnew), '-')

- d



More information about the SciPy-User mailing list