I have a data set with the first column is the x data (wavelenght) and the second column is the y data (relative intensity).
I wish to interpolate it on to another x_new-data but my problem is that splrep returns nan-values:
>>import numpy as np
>>from scipy.interpolate import splrep, splev
>>d = np.loadtxt("test.txt")
>>x,y = d[:,0],d[:,1]
>>
>>f = splrep( x,y,k=5 )
>>print f
>>(array([ 4501.19, 4501.19, 4501.19, ..., 7091.74, 7091.74, 7091.74]), array([ nan, nan, nan, ..., 0., 0., 0.]), 5)
It also happens when I don’t specify k. Any suggestions how to overcome this problem?
Your
xvalues probably contain duplicates, uses=...keyword argument to splrep to set a smoothing factor, because if this is not set the splines are supposed to go through every point exactly which is impossible with duplicates.It might be that they are not duplicates but just very close too.